Re: [15] RFR: 8244459: Optimize the hash map size in LocaleProviderAdapters

2020-05-05 Thread Mark Davis ☕️
I wouldn't worry too much about over 2^29 either. However, the number of possible valid language tags is much larger than people think, since any combination of multiple variants can occur). So even not counting the locale extensions, it is over 2^129 (my rough calculation). Mark On Tue, May 5,

Re: [15] RFR: 8244459: Optimize the hash map size in LocaleProviderAdapters

2020-05-05 Thread naoto . sato
Hi Stuart, On 5/5/20 4:29 PM, Stuart Marks wrote: As for Naoto's changeset, I don't think it should be held up while we bikeshed this. :-) I'm ok with whatever he decides. I don't think the number of language tags exceed 2^29, unless languages in the whole universe are counted :-) So I would

Re: [15] RFR: 8244459: Optimize the hash map size in LocaleProviderAdapters

2020-05-05 Thread Stuart Marks
Hm, interesting, good catch Peter! Very subtle. The time-honored (int) (expected / 0.75f) + 1 appears in several places around the JDK. I think most people (including me) just copy it, because it's "good enough" for most cases. I'm a little concerned about (expectedSize * 4 + 2) / 3

Re: [15] RFR: 8244459: Optimize the hash map size in LocaleProviderAdapters

2020-05-05 Thread Joe Wang
On 5/5/2020 2:08 PM, naoto.s...@oracle.com wrote: Thanks, all. I didn't see this coming! +1, just when one might think it was just a minor tweak... ;-) If I understand the discussion correctly, Peter's suggestion is the most optimal (Mark, your formula produces 1 for the expected size is

Re: [15] RFR: 8244459: Optimize the hash map size in LocaleProviderAdapters

2020-05-05 Thread naoto . sato
Thanks, all. I didn't see this coming! If I understand the discussion correctly, Peter's suggestion is the most optimal (Mark, your formula produces 1 for the expected size is 0, although it won't be happening in this particular case). And Joe, thank you for finding my silly mistake :-) So her

Re: [15] RFR: 8244459: Optimize the hash map size in LocaleProviderAdapters

2020-05-05 Thread Peter Levart
On 5/5/20 8:29 PM, Joe Wang wrote: Hi Naoto, It seems you've missed the parentheses in : Set tagset = new HashSet<>(tokens.countTokens() * 4 + 2 / 3); vs Set tagset = new HashSet<>((tokens.countTokens() * 4 + 2) / 3); -Joe Just a reminder to Naoto: In all this excitement, don't loose track

Re: [15] RFR: 8244459: Optimize the hash map size in LocaleProviderAdapters

2020-05-05 Thread Peter Levart
There's more... Guava (and JDK in copy constructor) formula:     (int) ((float) expectedSize / 0.75f + 1.0f) is not the same as Naoto's formula:     (int) (expectedSize / 0.75f) + 1 Notice that Naoto does addition of 1 in integer arithmetic after conversion to int, while Guava/JDK does in

Re: [15] RFR: 8244459: Optimize the hash map size in LocaleProviderAdapters

2020-05-05 Thread Peter Levart
On 5/5/20 9:41 PM, Martin Buchholz wrote: Hi Peter, Are you saying guava has a tiny bug? If it was just 1 too much when expected size is a multiple of 3 then that would not be a bug, just sub-optimal calculation. And the same calculation is performed also in JDK when a copy constructor is

Re: [15] RFR: 8244459: Optimize the hash map size in LocaleProviderAdapters

2020-05-05 Thread Martin Buchholz
Hi Peter, Are you saying guava has a tiny bug? On Tue, May 5, 2020 at 12:12 PM Peter Levart wrote: > Hi Martin, > On 5/5/20 8:26 PM, Martin Buchholz wrote: > > See related: > > https://guava.dev/releases/23.0/api/docs/com/google/common/collect/Maps.html#newHashMapWithExpectedSize-int- > > > Thi

Re: [15] RFR: 8244459: Optimize the hash map size in LocaleProviderAdapters

2020-05-05 Thread Peter Levart
Hi Martin, On 5/5/20 8:26 PM, Martin Buchholz wrote: See related: https://guava.dev/releases/23.0/api/docs/com/google/common/collect/Maps.html#newHashMapWithExpectedSize-int- This is basically the same calculation (or at least gives same result) as Naoto did (without the max part): Naoto:

Re: [15] RFR: 8244152: Remove unnecessary hash map resize in LocaleProviderAdapters

2020-05-05 Thread Mark Davis ☕️
> (int)(tokens.countTokens() / 0.75f) + 1 > (tokens.countTokens() * 4 + 2) / 3 if you want A * X / Y, rounded up, you can use (A * X - 1 ) / Y + 1 eg where X/Y = 4/3, 0 => 0 1 => 2 2 => 3 3 => 4 4 => 6 ... Mark On Tue, May 5, 2020 at 9:48 AM Peter Levart wrote: > Hi Naoto, > > On 4/30/20 1

Re: [15] RFR: 8244459: Optimize the hash map size in LocaleProviderAdapters

2020-05-05 Thread Joe Wang
Hi Naoto, It seems you've missed the parentheses in : Set tagset = new HashSet<>(tokens.countTokens() * 4 + 2 / 3); vs Set tagset = new HashSet<>((tokens.countTokens() * 4 + 2) / 3); -Joe On 5/5/2020 11:01 AM, naoto.s...@oracle.com wrote: And here is the fix. Please review. http://cr.openjdk.

Re: [15] RFR: 8244459: Optimize the hash map size in LocaleProviderAdapters

2020-05-05 Thread Martin Buchholz
See related: https://guava.dev/releases/23.0/api/docs/com/google/common/collect/Maps.html#newHashMapWithExpectedSize-int- On Tue, May 5, 2020 at 11:03 AM wrote: > And here is the fix. Please review. > > http://cr.openjdk.java.net/~naoto/8244459/webrev.00/ > > Naoto > > On 5/5/20 10:25 AM, naoto.

[15] RFR: 8244459: Optimize the hash map size in LocaleProviderAdapters

2020-05-05 Thread naoto . sato
And here is the fix. Please review. http://cr.openjdk.java.net/~naoto/8244459/webrev.00/ Naoto On 5/5/20 10:25 AM, naoto.s...@oracle.com wrote: Hi Peter, You are correct. Thanks. I'll remove that initial value of 16. Naoto On 5/5/20 9:37 AM, Peter Levart wrote: Hi Naoto, On 4/30/20 12:18

Re: [15] RFR: 8244152: Remove unnecessary hash map resize in LocaleProviderAdapters

2020-05-05 Thread naoto . sato
Hi Peter, You are correct. Thanks. I'll remove that initial value of 16. Naoto On 5/5/20 9:37 AM, Peter Levart wrote: Hi Naoto, On 4/30/20 12:18 AM, naoto.s...@oracle.com wrote: Hello, Please review this small fix to the following issue: https://bugs.openjdk.java.net/browse/JDK-8244152 Th

Re: [15] RFR: 8244152: Remove unnecessary hash map resize in LocaleProviderAdapters

2020-05-05 Thread Peter Levart
Hi Naoto, On 4/30/20 12:18 AM, naoto.s...@oracle.com wrote: Hello, Please review this small fix to the following issue: https://bugs.openjdk.java.net/browse/JDK-8244152 The proposed changeset is located at: https://cr.openjdk.java.net/~naoto/8244152/webrev.00/ The hash map used there didn't