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

Obsolete warning: ITA_INEFFICIENT_TO_ARRAY #993

Open
kofa73 opened this issue Jul 24, 2019 · 5 comments
Open

Obsolete warning: ITA_INEFFICIENT_TO_ARRAY #993

kofa73 opened this issue Jul 24, 2019 · 5 comments
Assignees

Comments

@kofa73
Copy link

kofa73 commented Jul 24, 2019

https://spotbugs.readthedocs.io/en/stable/bugDescriptions.html#ita-method-uses-toarray-with-zero-length-array-argument-ita-inefficient-to-array

According to detailed analysis by Aleksey Shipilëv (https://shipilev.net/blog/2016/arrays-wisdom-ancients/), the zero-length initialisation has been faster than pre-sized since at least Java 8. IntelliJ Idea has been updated to recommend the use of the new style now (when using recent versions of Java), see https://github.com/JetBrains/intellij-community/blob/master/plugins/InspectionGadgets/src/inspectionDescriptions/ToArrayCallWithZeroLengthArrayArgument.html.

@welcome
Copy link

welcome bot commented Jul 24, 2019

Thanks for opening your first issue here! 😃
Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in this issue.

@hazendaz hazendaz self-assigned this Aug 19, 2023
@hazendaz
Copy link
Member

read most of that but its more about knowing what data you are working with so GC doesn't happen right away. They seem to even imply that throughout. If you know your size, and I mean know it, then its better to size it correctly to start with. I don't think any scanners actually changed either in regards. Given 4 years now and no response here, going to close. If still a considered problem, please find new info on the subject as profiling can be hard. I don't see ramp ups to prove with certainty their data is 100% accurate and even some of their numbers are off a bit to their conclusions. When dealing with big record sets which is more the norm when copying, it still appears even on their own results that sizing it was better. Its the really small ones that is not true and that I'd agree since jvm is optimized for 16 by default regardless so less than that would go against its optimization and there is no example here in this issue to even state what type we were dealing with. At any rate, mostly closing as really old and no one responded.

@kofa73
Copy link
Author

kofa73 commented Aug 20, 2023

its more about knowing what data you are working with so GC doesn't happen right away

I don't understand this. I think what Aleksey showed is that zeroing out the newly allocated array takes time (an even more significant part of toArray(new T[size]) vs toArray(new T[0]) story is zeroing elimination), which is not related to GC. The GC aspect of the measurement is detailed here: https://shipilev.net/blog/2016/arrays-wisdom-ancients/#_not_an_allocation_pressure

I don't see ramp ups to prove with certainty their data is 100% accurate

The tests were run using JMH. The author of the article is one of the maintainers:

Aleksey is working on Java performance for 15+ years. Today he is employed by AWS, where he does OpenJDK development and performance work. Aleksey develops and maintains a number of OpenJDK subprojects, including JMH, JOL, and JCStress.
(https://shipilev.net/)

You can see the warm-up (is that what you mean by ramp-up?) in the benchmark section:

@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)

Or, if you meant measurements with an increasing array size:

    @Param({"0", "1", "10", "100", "1000"})
    int size;

@hazendaz
Copy link
Member

hazendaz commented Aug 20, 2023 via email

@hazendaz
Copy link
Member

reopening, see mybatis/mybatis-3#2925, has some more information on the subject. trade off on GC I noted is not worth the results. However, need a PR for this...

@hazendaz hazendaz reopened this Aug 27, 2023
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

No branches or pull requests

2 participants