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

#220 do *not* use Arrays.copyOf(), performance seems to be inferior #224

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

winfriedgerlach
Copy link
Contributor

No description provided.

@cowtowncoder
Copy link
Member

@winfriedgerlach Ok no real change wrt Arrays.copyOf(), but curious as to if you have something that points to such performance difference? Or did you do micro-benchmark?
(would have like used it mostly for bit more compact code)

@winfriedgerlach
Copy link
Contributor Author

@cowtowncoder Very good question that I don't have the perfect answer for.

Very old comments (Joshua Bloch) say .clone() is the fastest way to clone an array. This is already challenged in some of the answers to that question. Most published benchmarks of "medium age" (e.g. some years ago) find that System.arrayCopy() is fastest.

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 Arrays.copy() and System.arrayCopy() (note the absence of the JVM version under test...):
https://www.baeldung.com/java-system-arraycopy-arrays-copyof-performance

My own micro (and a little less micro benchmarks) showed System.arrayCopy() ahead most of the times, sometimes on same level as clone()/Arrays.copyOf().

As Jackson currently supports every Java version from Java 8 to 23, I recon it is safer to stick with System.arrayCopy() for now when optimizing for performance, even if there is probably almost no performance difference when using the most current (=2024) Java versions.

I definitely have to agree that the code is nicer with Arrays.copyOf()though, see cfe59fb

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

Successfully merging this pull request may close these issues.

2 participants