-
-
Notifications
You must be signed in to change notification settings - Fork 812
Optimize TextBuffer.contentsAsDouble() #346
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
Comments
I'd be happy to merge PR if you have something that can be shown to materially improve performance. My understanding, for what that is worth, is that actual decoding from 10-based textual representation into binary floating point number is often an order of magnitude or more slower than cost of memory allocation (and resulting) GC. https://pdfs.semanticscholar.org/9039/1d5a4b445b27cf8ab68ca10c0d37b69b39fc.pdf but that gives you an idea of complexity. Or checkout JDK code. It's.... complicated. |
I know :-) I didn't suggest it was easy. Just wanted to document that in this case the String creation is significant in terms of garbage. Which matters if you are short on memory. |
My point however is that the only case where this would seem to matter is if trying to absolutely minimize any memory allocations. I agree in that JDK could (and ideally should) have provided entry point from |
Looking into the bottlenecks of parsing GeoJSON with Jackson I've also found There is a library that can parse doubles significantly faster than Java own built-in. It looks a bit experimental so I hoped to just configure/subclass/manipulate Jackson's bits... got close enough, but a private static JsonFactory factory = new JsonFactory() {
@Override
protected IOContext _createContext(Object srcRef, boolean resourceManaged) {
return new IOContext(this._getBufferRecycler(), srcRef, resourceManaged) {
@Override
public TextBuffer constructTextBuffer() {
return new TextBuffer(this._bufferRecycler) { // bummer... final
@Override
public double contentsAsDouble() throws NumberFormatException {
// eventually call FastDoubleParser here
return super.contentsAsDouble();
}
};
}
};
}
}; Pity, parsing complex GeoJSON polygons requires reading a lot of coordinates, optimizing that step would help quite a bit. |
PRs would definitely be welcome. I am open to changes and could change that method in There are other ways to go about overriding behavior (via |
I think #577 actually covers this; closing. |
Currently TextBuffer contentsAsDouble will first create a string that is passed to Double.parseDouble().
I know floating point parsing is painful but if you are looking for optimization opportunities, this is one.

The text was updated successfully, but these errors were encountered: