You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[WIP] Optimization: Improve performance for repetitive lookup
CacheLookupTable leaves the bucket vacant when the object is freed.
Because of this, in the worst case, subscript have to perform full linear
search for all buckets.
Let's say we have a table like this:
bucket 0: obj1(hash: 0)
bucket 1: obj2(hash: 1)
bucket 2: nil
bucket 3: obj3(hash: 0)
bucket 4: nil
If obj1 is freed, it become:
bucket 0: nil
bucket 1: obj2(hash: 1)
bucket 2: nil
bucket 3: obj3(hash: 0)
bucket 4: nil
When looking-up obj3, the search starts from "bucket 0", thus it needs 3
iteration.
This patch moves the obj3 to "bucket 0" the first nil hole found.
So the next lookup doesn't need any iteration.
bucket 0: obj3(hash: 0)
bucket 1: obj2(hash: 1)
bucket 2: nil
bucket 3: nil
bucket 4: nil
0 commit comments