[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Suggestion : Use unique string type instead of two (short and long)
- From: 云风 <cloudwu@...>
- Date: Wed, 19 Jun 2019 23:32:59 +0800
在 2019年6月17日,23:41,Roberto Ierusalimschy <roberto@inf.puc-rio.br> 写道:
>> Maybe a 32bit id is enough, because we can rearrange the id during the gc process. It’s a little complicated, but I think it’s possible.
>
> Can you be more specific? It is easy for the GC to set a watermark
> (e.g., to keep the highest/lower id still in use), but that does
> not guarantee anything. We can also renumber all strings, paying
> the price for a little overhead in the first comparisons after each
> GC cycle.
>
We can use two id spaces: old space [0, 0x7fffffff] and young space [0x80000000, 0xffffffff]
At start of each gc cycle , allocate id from 0x80000000,and all the new strings are young.
For each gc cycle, we only renumber young strings ( all or a part ) to old by allocating the id from 0 at sweep stage.
When we need merge two id with the same values, we choose the lower one.
I think the highest old id would increase very slowly, because a young string may turns to old id when it compare to an old string with the same value.
When the highest old id exceed a very larger number, we can also renumber all to clear up.