Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve perf of float and double parsing in TextBuffer #1230

Merged
merged 10 commits into from
Apr 20, 2024

Conversation

pjfanning
Copy link
Member

@pjfanning pjfanning commented Mar 1, 2024

  • just an outline - not for merging
  • relates to Add char[] versions for NumberInput parseFloat, parseDouble, parseBigInteger #1229
  • In TextBuffer, when parsing floats and doubles, avoid creating Strings first
  • copies the logic of contentsAsString into the float and double methods so that we can best handle the various scenarios
    • if _resultString already exists, use it
    • if _resultArray already exists, parse from the array instead of creating a String
    • in the case that multiple segments are needed, we might as well fall back to contentsAsString in this case because we need to build a String with a StringBuilder anyway

@cowtowncoder is this a long the right lines? If so, I can add tests. If we get this done for floats and doubles, we can come back to make similar changes for other number types.

I'm aware that this does not address the deferred number parsing in ParserBase (where numbers can be stored as _numberString until we know what type we need). Storing the number as the wrong number type and later converting it to a different number type can lead to number conversion issues and can be more expensive.

@cowtowncoder
Copy link
Member

@pjfanning Yes, this is what I had in mind. I'll have a look and suggest some changes. Since we are not (yet) changing calling from ParserBase, I think this could actually go in 2.17, even.

I also think that we can remove some of deferral because calls to, say, getFloatValue() does explicitly establish target type -- but this is easy enough to verify with more time wrt 2.18 once 2.17 is out.
But that question is separate from work to make TextBuffer pass more optimal representation.

@pjfanning pjfanning changed the base branch from 2.17 to 2.18 March 26, 2024 18:59
@pjfanning pjfanning changed the title [DRAFT] improve perf of float and double parsing in TextBuffer improve perf of float and double parsing in TextBuffer Mar 26, 2024
@pjfanning pjfanning force-pushed the textbuffer-double-float-parse branch from 7bc8b89 to 64e25b2 Compare March 26, 2024 19:08
@cowtowncoder
Copy link
Member

I think I'll go ahead and merge this: it will be needed to tackle #1229.

@cowtowncoder cowtowncoder changed the title improve perf of float and double parsing in TextBuffer Improve perf of float and double parsing in TextBuffer Apr 20, 2024
@cowtowncoder cowtowncoder merged commit 8b87cc1 into FasterXML:2.18 Apr 20, 2024
5 checks passed
@cowtowncoder cowtowncoder added the 2.18 Issues planned at earliest for 2.18 label Apr 20, 2024
@cowtowncoder cowtowncoder added this to the 2.18.0 milestone Apr 20, 2024
@pjfanning pjfanning deleted the textbuffer-double-float-parse branch April 20, 2024 09:16
if (_inputStart >= 0) { // shared?
return NumberInput.parseDouble(_inputBuffer, _inputStart, _inputLen, useFastParser);
}
if (_currentSize == 0) { // all content in current segment!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug, actually -- should use _hasSegments instead! Fixed in #1313.

if (_inputStart >= 0) { // shared?
return NumberInput.parseFloat(_inputBuffer, _inputStart, _inputLen, useFastParser);
}
if (_currentSize == 0) { // all content in current segment!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, fixed in #1313

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.18 Issues planned at earliest for 2.18
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants