Add the basic version of WeakHashMap which replies on lazy deletion of key & value.
Created attachment 431061 [details] Patch
Pending ews, this approach looks good to me. But I also think we should add a counter, so that after N operations on a weak map, we iterate and clear all nulls. Such a counter maintains the average case amortized O(1) guarantee. And that way, when we talk about the need for a more intrusive way to clear nulls, we’ll compare against the best possible baseline and avoid premature optimization.
(In reply to Geoffrey Garen from comment #2) > Pending ews, this approach looks good to me. > > But I also think we should add a counter, so that after N operations on a > weak map, we iterate and clear all nulls. Such a counter maintains the > average case amortized O(1) guarantee. And that way, when we talk about the > need for a more intrusive way to clear nulls, we’ll compare against the best > possible baseline and avoid premature optimization. Which operations though? If done natively, that seems like it's gonna bloat the code size everywhere.
Created attachment 431100 [details] Fixed the builds
> > But I also think we should add a counter, so that after N operations on a > > weak map, we iterate and clear all nulls. Such a counter maintains the > > average case amortized O(1) guarantee. And that way, when we talk about the > > need for a more intrusive way to clear nulls, we’ll compare against the best > > possible baseline and avoid premature optimization. > > Which operations though? If done natively, that seems like it's gonna bloat > the code size everywhere. My straw man proposal would be all insertion, removal, and lookup operations. If that has a significant impact on code size, my second straw man proposal would be not to mark those functions inline. (I seriously doubt their value as inline functions on modern processors, since the cost is always going to be in the out of line lookup function.)
Note that I'm proposing an increment, a branch, and a function call. So, yes, a few bytes of code, but not a ton.
Created attachment 431187 [details] Added amortized deletion
Comment on attachment 431187 [details] Added amortized deletion r=me
Comment on attachment 431187 [details] Added amortized deletion Clearing flags on attachment: 431187 Committed r278803 (238760@main): <https://commits.webkit.org/238760@main>
All reviewed patches have been landed. Closing bug.
<rdar://problem/79227218>
Filed: Bug 227102 – [Win] TestWTF.WTF_WeakPtr.WeakHashMapIterators is crashing