• Seth Brenith's avatar
    Improve Script reuse in isolate compilation cache, part 1 · 25072178
    Seth Brenith authored
    Once the root SharedFunctionInfo for any Script gets its bytecode
    flushed, the Isolate's compilation cache currently evicts that entry, to
    reduce memory usage. However, the associated Script is likely still
    alive, since scripts often declare functions which outlive the initial
    evaluation of the script. If an identical script is loaded later, a
    duplicate Script is created for it, which can waste memory.
    
    In this change, I propose that the compilation cache keys can refer
    weakly to the Script. When the root SharedFunctionInfo gets old, instead
    of deleting the cache entry entirely, we can just drop the strong
    reference to the SharedFunctionInfo. A subsequent lookup in the cache
    will retrieve the Script instead of the root SharedFunctionInfo,
    indicating an opportunity to save some memory by reusing the existing
    Script.
    
    Eventually, all callers to CompilationCache::LookupScript should reuse
    the Script if possible. This change implements only the easy case of
    reusing the Script for synchronous parsing. Follow-up changes will be
    required for the TODO comments left by this change.
    
    Bug: v8:12808
    Change-Id: Ia8b0389441a682de9a43e73329049fd2e7835d3d
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3597106Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
    Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
    Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#80472}
    25072178
test-serialize.cc 180 KB