RFR: JDK-8292276 : Add named colors from CSS Color Module Level 4 [v38]
Alexey Ivanov
aivanov at openjdk.org
Tue Oct 10 20:32:10 UTC 2023
On Tue, 10 Oct 2023 15:11:24 GMT, Andy Goryachev <angorya at openjdk.org> wrote:
>>> would it make more sense to use a switch statement instead of a static map?
>>
>> I believe this was discussed somewhere… Looks like map provides better performance compared to `switch` statement. Fetching an element from a map gives a constant time, using a `switch` statement over strings would give a linear search time unless it's cleverly optimised by the compiler.
>>
>> @scientificware could point you to performance measurements, if there are ones. There were ones, if my memory serves me right.
>
> 1. I believe the switch uses hash value so it's not linear anymore
> 2. most of the time these colors will not be needed
>
> just a suggestion, anyway
I agree. Perhaps, we should reconsider it again.
The map takes up heap memory even if look up is done once, after the map is initialised, it's kept in memory forever. From this point of view, `switch` statement could be more efficient.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/9825#discussion_r1353278202
More information about the client-libs-dev
mailing list