Search code examples
garbage-collectionv8

I does not know why it is 25


[enter image description here][1]

[1]: https://i.sstatic.net/gg6E1.jpg Please tell me why it is 25.


Solution

  • First off: Please be descriptive when asking questions, and give some background.

    • Where did you encounter that code?
    • Do you care about the fact that there is a threshold at all? (E.g. "Why does V8's ShouldBePromoted function contain a check for remaining to-space capacity?")
    • Do you care about the specific value of the threshold? (E.g. "Why is the value of this threshold 25% and not 24%?")
    • Why do you care? Is there a problem or are you just curious?
    • Post text and code as text, not as images/screenshots.

    Giving some background helps you get better answers that actually address what you want to know!

    Secondly, this code must be from some ancient version of V8. It was deleted in 2014. Apparently someone had a reason to decide that it was better not to have it.

    All that said, the general answer would be: It's a heuristic that has presumably been found to work well at some point. The reasoning was probably that a generational GC is most efficient when only few objects survive scavenges. If an application has an allocation pattern where many young objects survive a scavenge, then it saves time to promote them to old-space immediately (otherwise they would get promoted soon anyway, which would be another copying operation). When implementing this general idea, you have to decide "how many objects is 'few' objects?"; old V8 happens to have chosen "a quarter of new-space size" here.