Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Key to refer to properties and cache hash code #634

Merged
merged 21 commits into from Jul 30, 2019

Conversation

lahma
Copy link
Collaborator

@lahma lahma commented Jul 14, 2019

I wanted to play with the idea that we use separate struct Key when referring to binding context or object properties. Now when we want to get variable counter, we build identifier which also holds calculated hash code. With this hash we can make subsequent searches faster when trying to find the correct context. Basically every object property of identifier lookup will require calculating hash code at least once. This also cleans up checking for our known commonly accessed properties where we don't want to build the dictionary unless necessary.

Preliminary results

NOTE now using .NET Core App 2.2 for benchmark project for both dev branch and this work

BenchmarkDotNet=v0.11.5, OS=Windows 10.0.18362
Intel Core i7-6820HQ CPU 2.70GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=2.2.300
  [Host]     : .NET Core 2.2.5 (CoreCLR 4.6.27617.05, CoreFX 4.6.27618.01), 64bit RyuJIT
  DefaultJob : .NET Core 2.2.5 (CoreCLR 4.6.27617.05, CoreFX 4.6.27618.01), 64bit RyuJIT

Esprima.Benchmark.SunSpiderBenchmark

Diff Method FileName Mean Gen 0 Gen 1 Gen 2 Allocated
Old Run 3d-cube 468.5 ms 11000.0000 1000.0000 - 50317752 B
New 396.9 ms (-15%) 11000.0000 (0%) 1000.0000 (0%) - 52010688 B (+3%)
Old Run 3d-morph 395.7 ms 11000.0000 2000.0000 - 71345344 B
New 357.0 ms (-10%) 11000.0000 (0%) 2000.0000 (0%) - 71347704 B (0%)
Old Run 3d-raytrace NA - - - -
New NA - - - -
Old Run access-binary-trees 175.1 ms 14000.0000 1000.0000 - 63774424 B
New 154.4 ms (-12%) 16000.0000 (+14%) 1000.0000 (0%) - 69496880 B (+9%)
Old Run access-fannkuch 1,282.4 ms 9000.0000 - - 39755568 B
New 1,196.9 ms (-7%) 9000.0000 (0%) - - 39757224 B (0%)
Old Run access-nbody 373.4 ms 12000.0000 - - 54428800 B
New 328.5 ms (-12%) 13000.0000 (+8%) - - 55555136 B (+2%)
Old Run access-nsieve 521.5 ms 13000.0000 3000.0000 - 76648328 B
New 454.6 ms (-13%) 13000.0000 (0%) 3000.0000 (0%) - 76649152 B (0%)
Old Run bitop(...)-byte [24] 284.6 ms 16000.0000 - - 70622440 B
New 256.6 ms (-10%) 18000.0000 (+13%) - - 77790824 B (+10%)
Old Run bitops-bits-in-byte 493.0 ms 11000.0000 - - 46549616 B
New 414.9 ms (-16%) 12000.0000 (+9%) - - 51567576 B (+11%)
Old Run bitops-bitwise-and 358.4 ms 9000.0000 - - 37761080 B
New 222.9 ms (-38%) 9000.0000 (0%) - - 37761192 B (0%)
Old Run bitops-nsieve-bits 447.1 ms 21000.0000 - - 92804376 B
New 415.2 ms (-7%) 21000.0000 (0%) - - 92805016 B (0%)
Old Run contr(...)rsive [21] 239.3 ms 18000.0000 - - 75932952 B
New 218.6 ms (-9%) 19000.0000 (+6%) - - 82878200 B (+9%)
Old Run crypto-aes 325.5 ms 5000.0000 1000.0000 - 24145568 B
New 307.1 ms (-6%) 5000.0000 (0%) 1000.0000 (0%) - 25208224 B (+4%)
Old Run crypto-md5 233.7 ms 22000.0000 1000.0000 - 95929104 B
New 213.0 ms (-9%) 24000.0000 (+9%) 1000.0000 (0%) - 103736728 B (+8%)
Old Run crypto-sha1 227.6 ms 16000.0000 2000.0000 - 69446824 B
New 199.2 ms (-12%) 17000.0000 (+6%) 2000.0000 (0%) - 73983016 B (+7%)
Old Run date-format-tofte 250.7 ms 15000.0000 - - 65456000 B
New 234.4 ms (-7%) 16000.0000 (+7%) - - 67688504 B (+3%)
Old Run date-format-xparb 262.0 ms 8000.0000 - - 34971552 B
New 256.9 ms (-2%) 8000.0000 (0%) - - 35492840 B (+1%)
Old Run math-cordic 743.5 ms 17000.0000 - - 75250632 B
New 562.5 ms (-24%) 18000.0000 (+6%) - - 79051496 B (+5%)
Old Run math-partial-sums 270.7 ms 7000.0000 - - 29441680 B
New 189.3 ms (-30%) 7000.0000 (0%) - - 29442920 B (0%)
Old Run math-spectral-norm 270.0 ms 11000.0000 - - 48407384 B
New 209.9 ms (-22%) 12000.0000 (+9%) - - 51370128 B (+6%)
Old Run regexp-dna 378.4 ms 1000.0000 1000.0000 1000.0000 20956752 B
New 327.2 ms (-14%) 1000.0000 (0%) 1000.0000 (0%) 1000.0000 (0%) 20967976 B (0%)
Old Run string-base64 196.9 ms 9000.0000 1000.0000 - 37953408 B
New 155.5 ms (-21%) 8000.0000 (-11%) 1000.0000 (0%) - 36906216 B (-3%)
Old Run string-fasta 362.8 ms 24000.0000 - - 102173304 B
New 289.1 ms (-20%) 24000.0000 (0%) - - 103047624 B (+1%)
Old Run string-tagcloud 160.4 ms 11000.0000 1000.0000 - 59946720 B
New 136.9 ms (-15%) 11000.0000 (0%) 1000.0000 (0%) - 61025184 B (+2%)
Old Run string-unpack-code 148.3 ms 10000.0000 2000.0000 - 56713952 B
New 137.4 ms (-7%) 11000.0000 (+10%) 2000.0000 (0%) - 57728968 B (+2%)
Old Run strin(...)input [21] 143.9 ms 7000.0000 1000.0000 - 30861704 B
New 116.6 ms (-19%) 7000.0000 (0%) 1000.0000 (0%) - 29710640 B (-4%)

Jint.Benchmark.ArrayBenchmark

Diff Method N Mean Gen 0 Gen 1 Gen 2 Allocated
Old Slice 100 377.5 us 172.3633 - - 706.25 KB
New 362.2 us (-4%) 172.3633 (0%) - - 707.81 KB (0%)
Old Concat 100 506.2 us 187.5000 - - 769.53 KB
New 502.7 us (-1%) 187.5000 (0%) - - 771.09 KB (0%)
Old Unshift 100 20,483.0 us 3593.7500 - - 14814.06 KB
New 18,902.0 us (-8%) 3593.7500 (0%) - - 14821.88 KB (0%)
Old Push 100 8,807.1 us 390.6250 - - 1603.91 KB
New 6,856.9 us (-22%) 390.6250 (0%) - - 1614.06 KB (+1%)
Old Index 100 9,807.6 us 437.5000 - - 1824.22 KB
New 8,092.2 us (-17%) 437.5000 (0%) - - 1837.5 KB (+1%)
Old Map 100 3,309.8 us 523.4375 - - 2149.22 KB
New 3,301.6 us (0%) 539.0625 (+3%) - - 2216.41 KB (+3%)
Old Apply 100 604.5 us 202.1484 - - 828.91 KB
New 540.7 us (-11%) 203.1250 (0%) - - 832.03 KB (0%)
Old JsonStringifyParse 100 4,516.0 us 1289.0625 - - 5303.13 KB
New 4,558.7 us (+1%) 1289.0625 (0%) - - 5308.59 KB (0%)
Old FilterWithString 100 34,567.6 us 3400.0000 - - 14042.97 KB
New 35,521.2 us (+3%) 3600.0000 (+6%) - - 14827.34 KB (+6%)

Jint.Benchmark.ArrayStressBenchmark

Diff Method N Mean Gen 0 Gen 1 Gen 2 Allocated
Old Jint 20 492.7 ms 59000.0000 1000.0000 - 241.1 MB
New 397.3 ms (-19%) 59000.0000 (0%) 1000.0000 (0%) - 241.12 MB (0%)

Jint.Benchmark.DromaeoBenchmark

Diff Method FileName Mean Gen 0 Gen 1 Gen 2 Allocated
Old Run dromaeo-3d-cube 59.03 ms 1222.2222 222.2222 - 7417.87 KB
New 52.64 ms (-11%) 1400.0000 (+15%) 400.0000 (+80%) - 7787.58 KB (+5%)
Old Run dromaeo-core-eval 13.02 ms 78.1250 - - 377.66 KB
New 11.81 ms (-9%) 78.1250 (0%) - - 379.72 KB (+1%)
Old Run dromaeo-object-array 155.12 ms 41500.0000 1500.0000 250.0000 174932.15 KB
New 141.27 ms (-9%) 41500.0000 (0%) 1500.0000 (0%) 250.0000 (0%) 174934.22 KB (0%)
Old Run droma(...)egexp [21] 688.50 ms 52000.0000 32000.0000 21000.0000 413991.23 KB
New 682.69 ms (-1%) 47000.0000 (-10%) 28000.0000 (-13%) 18000.0000 (-14%) 407871.45 KB (-1%)
Old Run droma(...)tring [21] 811.74 ms 92000.0000 51000.0000 48000.0000 1378058.55 KB
New 746.38 ms (-8%) 90000.0000 (-2%) 49000.0000 (-4%) 46000.0000 (-4%) 1378271.16 KB (0%)

Jint.Benchmark.EvaluationBenchmark

Diff Method N Mean Gen 0 Gen 1 Gen 2 Allocated
Old Jint 20 808.5 us 138.6719 - - 569.69 KB
New 805.3 us (0%) 139.6484 (+1%) - - 575.16 KB (+1%)

Jint.Benchmark.MinimalScriptBenchmark

Diff Method N Mean Gen 0 Gen 1 Gen 2 Allocated
Old Jint 10 23.98 us 8.7891 - - 36.09 KB
New 26.34 us (+10%) 8.8196 (0%) - - 36.17 KB (0%)

Jint.Benchmark.StopwatchBenchmark

Diff Method N Mean Gen 0 Gen 1 Gen 2 Allocated
Old Jint 1 905.0 ms 12000.0000 - - 51.61 MB
New 728.0 ms (-20%) 13000.0000 (+8%) - - 54.02 MB (+5%)

Jint.Benchmark.UncacheableExpressionsBenchmark

Diff Method N Mean Gen 0 Gen 1 Gen 2 Allocated
Old Benchmark 500 230.6 ms 30333.3333 333.3333 - 122.59 MB
New 214.4 ms (-7%) 32000.0000 (+5%) 2333.3333 (+600%) - 128.79 MB (+5%)

@lahma lahma changed the title [WIP] Use Identifier to refer to properties [WIP] Use Key to refer to properties and cache hash code Jul 21, 2019
@lahma lahma changed the title [WIP] Use Key to refer to properties and cache hash code Use Key to refer to properties and cache hash code Jul 22, 2019
@lahma lahma requested a review from sebastienros July 22, 2019 18:52
@sebastienros sebastienros merged commit 00d91f6 into sebastienros:dev Jul 30, 2019
@lahma lahma deleted the perf/identifier branch July 31, 2019 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants