Closed kraendavid closed 1 year ago
Hi @chrisco484 HashSet is faster lookup than Concurrent versions - that is the reason for using HashSet. But since this is used on concurrent environment we have to make field volatile and assign a new temporary HashSet when changing the content of the HashSet. So we want the fast lookup from HashSet - but still work in concurrent environment. And this is all due to the fact that this set very fast will become stable and fully initialized - and thus only have lookup against it. So we take the cost of being a little slower until fully initialized - but once initialized it is the fastest at runtime. Did that explain it?
Hi @chrisco484 Did that explain it?
@kraendavid Yes, that explains it, thanks.
We have a massive enterprise app with ~3500 persistent classes so I was worried that the HashSet "copy from collection" constructor will be doing a lot of copying up until the point that initialization of all classes is complete.
Probably a case of short term pain for long term gain ;)
@kraendavid I wasn't sure what the purpose of the temporary 'updated' Set was. I'm sure there's a good reason but I couldn't work it out myself. Maybe due to recursion a recursive call needs to see the original Set? (but then couldn't that be achieved by only adding to the Set after the recursive call?) - don't know but losing sleep not being able to work it out ;)