-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
Performance tweaks #220
Comments
…StartChar() for better performance
…nferior to System.arrayCopy() + cleanup
Correct, all use of Cool stuff, will go through PRs. |
More details regarding Very old comments (Joshua Bloch) say Things seem to have changed quite a lot in the JDK recently (~beginning of 2023), so different Java versions may perform considerably differently:
Other quite new (2024) benchmarks find no significant difference between My own micro (and a little less micro) benchmarks showed As Jackson currently supports every Java version from Java 8 to 23, I recon it is safer to stick with I definitely have to agree that the code is nicer with |
@cowtowncoder in oldSize + (oldSize << 1) This looked a bit odd to me, as in many other places in the source code you increase array size by 50% only, e.g. len + (len >> 1) Is this intentional or maybe a typo ( |
Whoa! That sounds more like a bug indeed: unless some comment explicitly states otherwise, and I don't there is. So it should be shift-right to get +50% increase. |
Woodstox already features impressive performance optimizations, to which I would like to add small ones. I will submit in individual PRs, so we can discuss the changes separately.
I benchmarked with a JMH test using namespace-aware StAX-parsing with very little value extraction, other use-cases may show less significant improvements (but still benefit slightly).
WstxInputData.isNameStartChar(char)
andWstxInputData.isNameStartChar(char)
as hotspots. I suggest to make the common case (ASCII) slightly faster there by using aboolean
lookup table. This takes ~256 bytes of extra memory, but I suppose that this a reasonable trade-off. I benchmarked with different JVM versions and results varied, but my JMH test showed improvements of e.g. ~3%, sometimes better.StringBuffer
withStringbuilder
. The latter is well-known to be faster due to lack of synchronization. If my analysis is correct,Stringbuffer
is never used in a place where thread-safety is relevant, so it can safely be replaced. This has already been done instax2-api
, just a leftover in woodstox I guess.Bucket
should be fine and faster than calling getters.Approaches that did not work (maybe someone else tries with different results?):
Arrays.copyOf()
or just.clone()
(called byArrays.copyOf()
in newer Java versions) instead ofSystem.arrayCopy()
for cloning arrays: While theoretically.clone()
should be fastest (also according to Joshua Bloch in a quite old statement), my microbenchmarking showed no significant difference, oftenSystem.arrayCopy()
was even faster. But the code reads nicer (shorter, easier to understand), I have to admit. (more details see comment below)(1 << currToken) & MASK_GET_TEXT_XXX
) also for masks with just 2 different types. This seems to perform worse than justtype == A || type == B
.Attribute.getQName()
seems to have optimization potential, but it's not a hotspot.The text was updated successfully, but these errors were encountered: