On Mon, 27 Feb 2023 11:33:38 GMT, Andrey Turbanov <aturba...@openjdk.org> wrote:

> `LinkedList` is used as a field 
> `jdk.tools.jimage.JImageTask.OptionsValues#jimages`
> It's created, filled (with `add`) and then iterated. No removes from the head 
> or something like this. `ArrayList` should be preferred as more efficient and 
> widely used (more chances for JIT) collection.

I guess I should weigh in because I'm mentioned here by tweet.

The main point of "stop using LinkedList" (from the tweet) is in new code. If 
you're writing new code and get bogged down thinking, "Hm, should I use a 
LinkedList or ArrayList here?" then you should probably just use ArrayList and 
move on. There are few use cases where LinkedList is preferable to ArrayList, 
and most people won't ever see them.

That doesn't justify replacing existing usages of ArrayList with LinkedList. 
The proximate question to ask here is, "Does this change improve the JDK?" I 
don't see any such justification here. Functionally the replacement is intended 
to be the same, so this doesn't fix any actual bug. The performance is 
supposedly better, but it's unclear whether this **actually** matters in this 
case. However, there are risks and costs associated with such changes, 
including the possibility of unforeseen behavioral changes that result in test 
failures, and the cost of reviewer time.

The only benefit mentioned is that people look at the JDK and see LinkedList 
being used so they think it's OK to use LinkedList in their own code. This is 
quite tenuous. If you want people to stop using LinkedList, it will be much 
more effective to get <your favorite tutorial site> to say "use ArrayList 
instead of LinkedList" instead of trying to remove uses of it from the JDK.

-------------

PR: https://git.openjdk.org/jdk/pull/12760

Reply via email to