• Tobias Tebbi's avatar
    [runtime] avoid trim/grow loop when adding and removing one element · cd33ec55
    Tobias Tebbi authored
    We currently grow the backing store to (old_capacity*1.5)+16 if we exceed capacity, 
    but shrink the capacity to the current length when 2*length <= capacity.
    For short arrays (up to length 32), this can lead to a copy on every operation when using push/pop or push/shift.
    
    Example:
    Array of length 32, capacity 32
    push
    Array grown to length 33, capacity 32*1.5+16 = 64
    pop
    Array trimmed to length 32, capacity 32 because 2*32 <= 64
    ...
    
    This CL leaves additional slag space when calling pop and restricts the trimming to backing stores with at least 16 elements to prevent excessive re-trimming on short arrays.
    
    Bug: 
    Change-Id: I9dd13e5e2550c7ac819294c8e29f04c8855e02a4
    Reviewed-on: https://chromium-review.googlesource.com/502911
    Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
    Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#45324}
    cd33ec55
Name
Last commit
Last update
benchmarks Loading commit data...
build_overrides Loading commit data...
docs Loading commit data...
gni Loading commit data...
gypfiles Loading commit data...
include Loading commit data...
infra Loading commit data...
samples Loading commit data...
src Loading commit data...
test Loading commit data...
testing Loading commit data...
third_party Loading commit data...
tools Loading commit data...
.clang-format Loading commit data...
.gitignore Loading commit data...
.gn Loading commit data...
.ycm_extra_conf.py Loading commit data...
AUTHORS Loading commit data...
BUILD.gn Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
ChangeLog Loading commit data...
DEPS Loading commit data...
DEPS.chromium Loading commit data...
LICENSE Loading commit data...
LICENSE.fdlibm Loading commit data...
LICENSE.strongtalk Loading commit data...
LICENSE.v8 Loading commit data...
LICENSE.valgrind Loading commit data...
Makefile Loading commit data...
Makefile.android Loading commit data...
OWNERS Loading commit data...
PRESUBMIT.py Loading commit data...
README.md Loading commit data...
WATCHLISTS Loading commit data...
codereview.settings Loading commit data...
snapshot_toolchain.gni Loading commit data...