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

[Merged by Bors] - Implement constant folding optimization #2679

Closed
wants to merge 1 commit into from

Conversation

HalidOdat
Copy link
Member

@HalidOdat HalidOdat commented Mar 16, 2023

This PR implements an optimizer, It currently implements the constant folding optimization. this optimization is responsible for "folding"/evaluating constant expressions.

For example:

let x = ((1 + 2 + -4) * 8) << 4

Generates the following instruction(s) (cargo run -- -t):

000000    0000    PushOne
000001    0001    PushInt8                   2
000003    0002    Add
000004    0003    PushInt8                   4
000006    0004    Neg
000007    0005    Add
000008    0006    PushInt8                   8
000010    0007    Mul
000011    0008    PushInt8                   4
000013    0009    ShiftLeft
000014    0010    DefInitLet                 0000: 'x'

With constant folding it generates the following instruction(s) (cargo run -- -t -O):

000000    0000    PushInt8                   -128
000002    0001    DefInitLet                 0000: 'x'

It changes the following:

  • Implement WIP constant folding optimization, only works with integers for now
  • Add --optimize, -O flag to boa_cli
  • Add --optimizer-statistics flag to boa_cli for optimizer statistics
  • Add --optimize, -O flag to boa_tester

After I finish with this, will try to implement other optimizations :)

@HalidOdat HalidOdat added performance Performance related changes and issues run-benchmark Label used to run banchmarks on PRs labels Mar 16, 2023
@HalidOdat HalidOdat changed the title Implement constant folding optmization Implement constant folding optimization Mar 16, 2023
@github-actions
Copy link

github-actions bot commented Mar 16, 2023

Test262 conformance changes

Test result main count PR count difference
Total 94,277 94,277 0
Passed 71,094 71,094 0
Ignored 17,324 17,324 0
Failed 5,859 5,859 0
Panics 0 0 0
Conformance 75.41% 75.41% 0.00%

@github-actions
Copy link

Benchmark for 5a33439

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 672.3±1.52ns 569.9±1.21ns -15.23%
Arithmetic operations (Execution) 543.5±0.40ns 260.9±0.73ns -52.00%
Arithmetic operations (Parser) 7.5±0.03µs 8.0±0.03µs +6.67%
Array access (Compiler) 1980.8±9.22ns 1939.3±7.11ns -2.10%
Array access (Execution) 8.8±0.01µs 8.5±0.03µs -3.41%
Array access (Parser) 15.8±0.03µs 16.3±0.05µs +3.16%
Array creation (Compiler) 2.8±0.01µs 2.8±0.01µs 0.00%
Array creation (Execution) 1254.5±2.25µs 1247.7±1.85µs -0.54%
Array creation (Parser) 18.9±0.04µs 19.9±0.09µs +5.29%
Array pop (Compiler) 5.5±0.02µs 5.3±0.01µs -3.64%
Array pop (Execution) 729.2±1.70µs 727.1±1.42µs -0.29%
Array pop (Parser) 169.2±0.20µs 176.2±0.33µs +4.14%
Boolean Object Access (Compiler) 1352.2±3.43ns 1357.7±10.14ns +0.41%
Boolean Object Access (Execution) 4.9±0.01µs 4.8±0.01µs -2.04%
Boolean Object Access (Parser) 20.2±0.03µs 20.7±0.07µs +2.48%
Clean js (Compiler) 5.7±0.02µs 5.7±0.03µs 0.00%
Clean js (Execution) 700.3±3.50µs 706.5±2.51µs +0.89%
Clean js (Parser) 40.3±0.07µs 41.3±0.13µs +2.48%
Create Realm 535.8±22.56µs 518.9±1.37µs -3.15%
Dynamic Object Property Access (Compiler) 2.3±0.01µs 2.3±0.02µs 0.00%
Dynamic Object Property Access (Execution) 5.6±0.01µs 5.4±0.02µs -3.57%
Dynamic Object Property Access (Parser) 14.0±0.05µs 14.5±0.07µs +3.57%
Fibonacci (Compiler) 3.5±0.01µs 3.4±0.01µs -2.86%
Fibonacci (Execution) 1240.3±3.05µs 1159.3±3.49µs -6.53%
Fibonacci (Parser) 22.7±0.03µs 23.3±0.07µs +2.64%
For loop (Compiler) 3.3±0.01µs 3.2±0.01µs -3.03%
For loop (Execution) 18.7±0.11µs 18.3±0.04µs -2.14%
For loop (Parser) 19.6±0.04µs 20.3±0.08µs +3.57%
Mini js (Compiler) 5.2±0.02µs 5.2±0.01µs 0.00%
Mini js (Execution) 647.2±3.20µs 648.9±12.03µs +0.26%
Mini js (Parser) 35.2±0.06µs 36.2±0.11µs +2.84%
Number Object Access (Compiler) 1290.5±8.79ns 1272.4±4.75ns -1.40%
Number Object Access (Execution) 3.8±0.01µs 3.7±0.01µs -2.63%
Number Object Access (Parser) 15.4±0.06µs 15.7±0.15µs +1.95%
Object Creation (Compiler) 2.1±0.01µs 2.1±0.00µs 0.00%
Object Creation (Execution) 5.3±0.01µs 5.1±0.01µs -3.77%
Object Creation (Parser) 12.4±0.03µs 12.8±0.05µs +3.23%
RegExp (Compiler) 2.3±0.01µs 2.3±0.01µs 0.00%
RegExp (Execution) 14.4±0.05µs 14.0±0.05µs -2.78%
RegExp (Parser) 13.6±0.02µs 13.9±0.03µs +2.21%
RegExp Creation (Compiler) 2.1±0.03µs 2.0±0.01µs -4.76%
RegExp Creation (Execution) 10.4±0.04µs 9.8±0.02µs -5.77%
RegExp Creation (Parser) 11.4±0.02µs 11.7±0.04µs +2.63%
RegExp Literal (Compiler) 2.3±0.02µs 2.3±0.01µs 0.00%
RegExp Literal (Execution) 14.5±0.06µs 13.9±0.04µs -4.14%
RegExp Literal (Parser) 15.4±0.03µs 15.3±0.07µs -0.65%
RegExp Literal Creation (Compiler) 2.1±0.00µs 2.0±0.00µs -4.76%
RegExp Literal Creation (Execution) 10.4±0.04µs 9.8±0.03µs -5.77%
RegExp Literal Creation (Parser) 13.1±0.02µs 12.9±0.03µs -1.53%
Static Object Property Access (Compiler) 2.1±0.00µs 2.1±0.01µs 0.00%
Static Object Property Access (Execution) 5.5±0.01µs 5.3±0.01µs -3.64%
Static Object Property Access (Parser) 13.4±0.03µs 13.8±0.59µs +2.99%
String Object Access (Compiler) 1763.9±7.58ns 1727.9±3.08ns -2.04%
String Object Access (Execution) 6.8±0.01µs 6.7±0.01µs -1.47%
String Object Access (Parser) 19.3±0.04µs 20.0±0.05µs +3.63%
String comparison (Compiler) 3.0±0.01µs 2.9±0.01µs -3.33%
String comparison (Execution) 4.8±0.02µs 4.7±0.01µs -2.08%
String comparison (Parser) 15.5±0.05µs 16.2±0.08µs +4.52%
String concatenation (Compiler) 2.4±0.01µs 2.3±0.01µs -4.17%
String concatenation (Execution) 4.5±0.01µs 4.3±0.01µs -4.44%
String concatenation (Parser) 10.5±0.03µs 11.0±0.04µs +4.76%
String copy (Compiler) 1975.6±5.43ns 1912.7±6.47ns -3.18%
String copy (Execution) 4.2±0.02µs 4.1±0.01µs -2.38%
String copy (Parser) 7.8±0.02µs 8.0±0.02µs +2.56%
Symbols (Compiler) 1464.5±9.29ns 1388.1±4.36ns -5.22%
Symbols (Execution) 4.2±0.01µs 4.2±0.01µs 0.00%
Symbols (Parser) 5.9±0.02µs 6.2±0.03µs +5.08%

@HalidOdat
Copy link
Member Author

I enabled optimizations by default for testing, so that's why there is an improvement in benchmarks (especially 50% improvement in arithmetic execution), there also seems to be some improvement in byte compiling probably because it has to generate less.

Optimizations should probably be disabled when benchmarking

@HalidOdat HalidOdat force-pushed the optimization/constant-folding branch from 19664ea to 29abb90 Compare March 17, 2023 18:43
@Razican
Copy link
Member

Razican commented Mar 17, 2023

Optimizations should probably be disabled when benchmarking

Hmmm it depends what do we want to benchmark. I would like to see optimized vs non-optimized end-to-end benchmarking of real-life code.

An arithmetic expression that is compile-time known will of course be optimized away a lot.

@github-actions
Copy link

Benchmark for 7a157f0

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 657.1±1.72ns 417.4±1.48ns -36.48%
Arithmetic operations (Execution) 544.9±0.77ns 102.1±2.60ns -81.26%
Arithmetic operations (Parser) 7.6±0.04µs 8.5±0.02µs +11.84%
Array access (Compiler) 1906.6±8.84ns 1887.0±12.87ns -1.03%
Array access (Execution) 8.6±0.03µs 8.4±0.12µs -2.33%
Array access (Parser) 15.8±0.10µs 15.5±0.36µs -1.90%
Array creation (Compiler) 2.9±0.00µs 2.8±0.18µs -3.45%
Array creation (Execution) 1243.3±4.93µs 1247.0±4.38µs +0.30%
Array creation (Parser) 19.0±0.20µs 19.3±1.63µs +1.58%
Array pop (Compiler) 5.3±0.01µs 4.9±0.04µs -7.55%
Array pop (Execution) 705.7±5.63µs 702.5±9.78µs -0.45%
Array pop (Parser) 174.2±1.27µs 167.0±3.92µs -4.13%
Boolean Object Access (Compiler) 1324.3±2.16ns 1309.0±10.17ns -1.16%
Boolean Object Access (Execution) 4.9±0.01µs 4.8±0.07µs -2.04%
Boolean Object Access (Parser) 20.3±0.06µs 20.2±0.35µs -0.49%
Clean js (Compiler) 5.7±0.02µs 5.8±0.25µs +1.75%
Clean js (Execution) 706.5±3.28µs 674.7±18.50µs -4.50%
Clean js (Parser) 40.4±0.29µs 41.0±0.15µs +1.49%
Create Realm 512.3±3.61µs 522.5±15.65µs +1.99%
Dynamic Object Property Access (Compiler) 2.3±0.01µs 2.3±0.02µs 0.00%
Dynamic Object Property Access (Execution) 5.5±0.04µs 5.3±0.07µs -3.64%
Dynamic Object Property Access (Parser) 14.1±0.15µs 14.0±0.31µs -0.71%
Fibonacci (Compiler) 3.5±0.01µs 3.4±0.02µs -2.86%
Fibonacci (Execution) 1182.9±11.94µs 1165.8±11.60µs -1.45%
Fibonacci (Parser) 22.7±0.15µs 22.7±0.27µs 0.00%
For loop (Compiler) 3.2±0.01µs 3.1±0.01µs -3.13%
For loop (Execution) 18.4±0.03µs 18.4±0.11µs 0.00%
For loop (Parser) 19.8±0.07µs 19.9±0.26µs +0.51%
Mini js (Compiler) 5.1±0.06µs 5.1±0.01µs 0.00%
Mini js (Execution) 649.5±3.89µs 639.1±11.93µs -1.60%
Mini js (Parser) 35.3±0.12µs 35.7±0.06µs +1.13%
Number Object Access (Compiler) 1316.9±84.65ns 1254.2±9.00ns -4.76%
Number Object Access (Execution) 3.8±0.01µs 3.7±0.04µs -2.63%
Number Object Access (Parser) 15.4±0.06µs 15.1±0.34µs -1.95%
Object Creation (Compiler) 2.0±0.00µs 2.0±0.01µs 0.00%
Object Creation (Execution) 5.2±0.01µs 5.1±0.03µs -1.92%
Object Creation (Parser) 12.6±0.05µs 12.1±0.28µs -3.97%
RegExp (Compiler) 2.3±0.01µs 2.3±0.01µs 0.00%
RegExp (Execution) 14.2±0.10µs 14.2±0.05µs 0.00%
RegExp (Parser) 13.9±0.07µs 13.1±0.32µs -5.76%
RegExp Creation (Compiler) 2.1±0.07µs 1985.1±18.94ns -5.47%
RegExp Creation (Execution) 10.1±0.05µs 10.0±0.10µs -0.99%
RegExp Creation (Parser) 12.1±1.02µs 11.2±0.29µs -7.44%
RegExp Literal (Compiler) 2.3±0.01µs 2.2±0.02µs -4.35%
RegExp Literal (Execution) 14.3±0.05µs 14.2±0.15µs -0.70%
RegExp Literal (Parser) 15.5±0.08µs 14.8±0.37µs -4.52%
RegExp Literal Creation (Compiler) 2.1±0.07µs 1989.9±17.65ns -5.24%
RegExp Literal Creation (Execution) 10.1±0.10µs 10.0±0.05µs -0.99%
RegExp Literal Creation (Parser) 14.0±0.70µs 12.7±0.29µs -9.29%
Static Object Property Access (Compiler) 2.1±0.01µs 2.0±0.01µs -4.76%
Static Object Property Access (Execution) 5.4±0.01µs 5.3±0.02µs -1.85%
Static Object Property Access (Parser) 13.6±0.06µs 13.2±0.34µs -2.94%
String Object Access (Compiler) 1727.0±5.89ns 1693.0±6.36ns -1.97%
String Object Access (Execution) 6.7±0.01µs 6.8±0.24µs +1.49%
String Object Access (Parser) 19.6±0.16µs 19.7±0.22µs +0.51%
String comparison (Compiler) 2.9±0.00µs 2.9±0.01µs 0.00%
String comparison (Execution) 4.7±0.01µs 4.6±0.03µs -2.13%
String comparison (Parser) 15.5±0.11µs 15.4±0.25µs -0.65%
String concatenation (Compiler) 2.3±0.01µs 2.3±0.02µs 0.00%
String concatenation (Execution) 4.3±0.01µs 4.3±0.04µs 0.00%
String concatenation (Parser) 10.5±0.16µs 10.6±0.16µs +0.95%
String copy (Compiler) 1893.6±6.92ns 1879.3±17.16ns -0.76%
String copy (Execution) 4.1±0.01µs 4.2±0.24µs +2.44%
String copy (Parser) 8.1±0.30µs 7.5±0.22µs -7.41%
Symbols (Compiler) 1390.0±4.50ns 1381.1±3.92ns -0.64%
Symbols (Execution) 4.2±0.01µs 4.1±0.02µs -2.38%
Symbols (Parser) 6.0±0.06µs 6.0±0.10µs 0.00%

@github-actions
Copy link

Benchmark for 10ebc36

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 530.0±2.81ns 358.5±0.49ns -32.36%
Arithmetic operations (Execution) 413.0±0.39ns 92.7±0.13ns -77.55%
Arithmetic operations (Parser) 7.3±0.02µs 7.9±0.02µs +8.22%
Array access (Compiler) 1675.0±4.43ns 1663.1±4.97ns -0.71%
Array access (Execution) 7.6±0.02µs 7.6±0.02µs 0.00%
Array access (Parser) 16.0±0.03µs 16.1±0.03µs +0.63%
Array creation (Compiler) 2.6±0.04µs 2.4±0.00µs -7.69%
Array creation (Execution) 1128.2±12.22µs 1055.9±4.39µs -6.41%
Array creation (Parser) 19.2±0.07µs 19.0±0.05µs -1.04%
Array pop (Compiler) 4.2±0.01µs 4.2±0.01µs 0.00%
Array pop (Execution) 636.6±0.99µs 658.1±2.51µs +3.38%
Array pop (Parser) 159.5±0.37µs 161.9±0.13µs +1.50%
Boolean Object Access (Compiler) 1164.2±6.53ns 1176.5±3.92ns +1.06%
Boolean Object Access (Execution) 4.3±0.01µs 4.3±0.01µs 0.00%
Boolean Object Access (Parser) 19.5±0.03µs 19.3±0.04µs -1.03%
Clean js (Compiler) 5.3±0.02µs 5.1±0.02µs -3.77%
Clean js (Execution) 625.2±3.18µs 620.9±3.21µs -0.69%
Clean js (Parser) 39.9±0.07µs 39.8±0.06µs -0.25%
Create Realm 412.7±1.70µs 421.5±9.38µs +2.13%
Dynamic Object Property Access (Compiler) 1971.7±5.75ns 1940.4±5.63ns -1.59%
Dynamic Object Property Access (Execution) 4.9±0.01µs 4.8±0.01µs -2.04%
Dynamic Object Property Access (Parser) 14.5±0.04µs 14.3±0.08µs -1.38%
Fibonacci (Compiler) 3.1±0.01µs 3.1±0.00µs 0.00%
Fibonacci (Execution) 1083.9±2.15µs 1051.7±2.36µs -2.97%
Fibonacci (Parser) 22.6±0.03µs 22.3±0.05µs -1.33%
For loop (Compiler) 2.8±0.01µs 2.8±0.01µs 0.00%
For loop (Execution) 15.6±0.05µs 15.7±0.02µs +0.64%
For loop (Parser) 19.5±0.04µs 19.5±0.08µs 0.00%
Mini js (Compiler) 4.5±0.01µs 4.5±0.01µs 0.00%
Mini js (Execution) 573.2±2.92µs 574.6±2.68µs +0.24%
Mini js (Parser) 34.4±0.06µs 34.6±0.05µs +0.58%
Number Object Access (Compiler) 1091.4±5.95ns 1082.0±4.63ns -0.86%
Number Object Access (Execution) 3.4±0.01µs 3.3±0.01µs -2.94%
Number Object Access (Parser) 15.6±0.07µs 14.9±0.05µs -4.49%
Object Creation (Compiler) 1741.6±7.07ns 1744.6±2.04ns +0.17%
Object Creation (Execution) 4.6±0.01µs 4.4±0.01µs -4.35%
Object Creation (Parser) 12.9±0.03µs 12.7±0.05µs -1.55%
RegExp (Compiler) 1992.7±5.28ns 1988.2±3.61ns -0.23%
RegExp (Execution) 12.4±0.02µs 12.3±0.03µs -0.81%
RegExp (Parser) 13.9±0.03µs 13.5±0.04µs -2.88%
RegExp Creation (Compiler) 1769.5±3.11ns 1773.6±2.59ns +0.23%
RegExp Creation (Execution) 8.8±0.03µs 8.7±0.02µs -1.14%
RegExp Creation (Parser) 11.7±0.03µs 11.5±0.08µs -1.71%
RegExp Literal (Compiler) 1995.6±4.21ns 1987.2±3.95ns -0.42%
RegExp Literal (Execution) 12.4±0.02µs 12.3±0.02µs -0.81%
RegExp Literal (Parser) 14.8±0.04µs 14.6±0.04µs -1.35%
RegExp Literal Creation (Compiler) 1772.0±5.18ns 1766.4±2.06ns -0.32%
RegExp Literal Creation (Execution) 8.8±0.01µs 8.7±0.01µs -1.14%
RegExp Literal Creation (Parser) 12.6±0.03µs 12.5±0.04µs -0.79%
Static Object Property Access (Compiler) 1786.6±4.67ns 1749.8±2.34ns -2.06%
Static Object Property Access (Execution) 4.7±0.01µs 4.7±0.02µs 0.00%
Static Object Property Access (Parser) 13.9±0.07µs 13.7±0.03µs -1.44%
String Object Access (Compiler) 1505.7±8.76ns 1501.2±5.18ns -0.30%
String Object Access (Execution) 5.9±0.02µs 6.0±0.01µs +1.69%
String Object Access (Parser) 19.3±0.04µs 18.6±0.08µs -3.63%
String comparison (Compiler) 2.5±0.01µs 2.6±0.00µs +4.00%
String comparison (Execution) 4.1±0.02µs 3.9±0.01µs -4.88%
String comparison (Parser) 15.4±0.06µs 15.5±0.06µs +0.65%
String concatenation (Compiler) 2.0±0.00µs 2.0±0.00µs 0.00%
String concatenation (Execution) 3.8±0.02µs 3.7±0.00µs -2.63%
String concatenation (Parser) 10.4±0.04µs 10.5±0.02µs +0.96%
String copy (Compiler) 1661.2±3.91ns 1662.9±5.05ns +0.10%
String copy (Execution) 3.6±0.03µs 3.5±0.00µs -2.78%
String copy (Parser) 7.9±0.02µs 8.1±0.02µs +2.53%
Symbols (Compiler) 1212.4±6.59ns 1213.6±3.29ns +0.10%
Symbols (Execution) 3.6±0.02µs 3.6±0.17µs 0.00%
Symbols (Parser) 6.2±0.03µs 6.2±0.03µs 0.00%

@codecov
Copy link

codecov bot commented Mar 17, 2023

Codecov Report

Merging #2679 (7637200) into main (ceaea32) will increase coverage by 1.20%.
The diff coverage is 65.70%.

@@            Coverage Diff             @@
##             main    #2679      +/-   ##
==========================================
+ Coverage   50.81%   52.01%   +1.20%     
==========================================
  Files         400      397       -3     
  Lines       40121    39952     -169     
==========================================
+ Hits        20387    20781     +394     
+ Misses      19734    19171     -563     
Impacted Files Coverage Δ
boa_ast/src/expression/literal/array.rs 38.29% <0.00%> (+3.51%) ⬆️
boa_ast/src/expression/literal/mod.rs 80.00% <0.00%> (+0.68%) ⬆️
boa_ast/src/expression/operator/unary/mod.rs 57.14% <0.00%> (+4.51%) ⬆️
boa_cli/src/main.rs 0.00% <0.00%> (ø)
boa_engine/src/bytecompiler/expression/mod.rs 66.48% <0.00%> (-0.36%) ⬇️
boa_engine/src/lib.rs 78.20% <ø> (ø)
boa_tester/src/exec/mod.rs 0.00% <0.00%> (ø)
boa_tester/src/main.rs 0.00% <0.00%> (ø)
boa_engine/src/optimizer/mod.rs 61.70% <61.70%> (ø)
boa_engine/src/context/mod.rs 46.84% <69.23%> (+1.59%) ⬆️
... and 4 more

... and 54 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -45,7 +45,7 @@ jobs:
run: |
cd boa
mkdir ../results
cargo run --release --bin boa_tester -- run -v -o ../results/test262
cargo run --release --bin boa_tester -- run -O -v -o ../results/test262
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really cool! I do still need to dig into this more, but I had a question when I saw this. At least on any optimizer updates, should we run the tests on both optimized and non-optimized in our CI to insure that an update to one doesn't break something in another?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enabled optimization in test262 is just for testing for now.

At least on any optimizer updates, should we run the tests on both optimized and non-optimized in our CI to insure that an update to one doesn't break something in another?

Yes, completely agree! maybe we can configure to start test262 with optimizations when change to the optimizer module/directory happens (maybe reviewpad mentioned by @Razican can be used for this, since it has a nice way of checking if a directory contents are changed). And we should probably run it on main push and assert that the non-optimized and optimized are equal, just to be sure :)

@boa-dev boa-dev deleted a comment from github-actions bot Mar 18, 2023
@boa-dev boa-dev deleted a comment from github-actions bot Mar 18, 2023
@boa-dev boa-dev deleted a comment from github-actions bot Mar 18, 2023
@boa-dev boa-dev deleted a comment from github-actions bot Mar 18, 2023
@github-actions
Copy link

Benchmark for f8e7ae0

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 766.1±42.44ns 539.6±30.78ns -29.57%
Arithmetic operations (Execution) 698.2±59.68ns 121.6±7.28ns -82.58%
Arithmetic operations (Parser) 9.0±0.42µs 9.7±0.53µs +7.78%
Array access (Compiler) 2.2±0.10µs 2.3±0.17µs +4.55%
Array access (Execution) 10.2±0.62µs 10.1±0.54µs -0.98%
Array access (Parser) 18.9±1.07µs 18.9±0.46µs 0.00%
Array creation (Compiler) 3.4±0.22µs 3.4±0.20µs 0.00%
Array creation (Execution) 1329.6±53.02µs 1330.3±62.72µs +0.05%
Array creation (Parser) 23.1±1.75µs 24.6±2.03µs +6.49%
Array pop (Compiler) 5.7±0.68µs 5.6±0.28µs -1.75%
Array pop (Execution) 810.2±101.68µs 793.5±32.29µs -2.06%
Array pop (Parser) 201.1±7.04µs 207.2±13.41µs +3.03%
Boolean Object Access (Compiler) 1631.1±93.94ns 1640.5±97.49ns +0.58%
Boolean Object Access (Execution) 5.9±0.86µs 5.7±0.25µs -3.39%
Boolean Object Access (Parser) 23.4±0.97µs 23.5±1.92µs +0.43%
Clean js (Compiler) 6.9±0.54µs 6.9±0.41µs 0.00%
Clean js (Execution) 817.9±53.24µs 836.2±71.44µs +2.24%
Clean js (Parser) 48.3±1.97µs 50.8±3.54µs +5.18%
Create Realm 623.0±22.56µs 591.5±25.07µs -5.06%
Dynamic Object Property Access (Compiler) 2.7±0.13µs 2.6±0.18µs -3.70%
Dynamic Object Property Access (Execution) 6.6±0.36µs 6.3±0.37µs -4.55%
Dynamic Object Property Access (Parser) 17.1±0.71µs 18.3±0.94µs +7.02%
Fibonacci (Compiler) 4.2±0.16µs 4.2±0.28µs 0.00%
Fibonacci (Execution) 1482.4±72.72µs 1498.2±97.91µs +1.07%
Fibonacci (Parser) 27.0±1.51µs 28.0±0.91µs +3.70%
For loop (Compiler) 3.8±0.22µs 3.9±0.25µs +2.63%
For loop (Execution) 21.2±0.70µs 21.7±1.19µs +2.36%
For loop (Parser) 22.9±1.13µs 24.1±2.38µs +5.24%
Mini js (Compiler) 6.1±0.40µs 6.1±0.25µs 0.00%
Mini js (Execution) 724.7±29.99µs 717.1±33.72µs -1.05%
Mini js (Parser) 42.3±2.59µs 43.5±2.54µs +2.84%
Number Object Access (Compiler) 1495.7±65.60ns 1525.5±113.17ns +1.99%
Number Object Access (Execution) 4.6±1.05µs 4.4±0.26µs -4.35%
Number Object Access (Parser) 18.1±0.93µs 18.2±0.60µs +0.55%
Object Creation (Compiler) 2.4±0.16µs 2.5±0.17µs +4.17%
Object Creation (Execution) 6.5±0.88µs 6.2±0.49µs -4.62%
Object Creation (Parser) 15.0±0.51µs 15.2±0.54µs +1.33%
RegExp (Compiler) 2.7±0.42µs 2.8±0.16µs +3.70%
RegExp (Execution) 16.9±0.75µs 17.8±1.08µs +5.33%
RegExp (Parser) 16.4±0.71µs 16.8±0.87µs +2.44%
RegExp Creation (Compiler) 2.4±0.15µs 2.4±0.07µs 0.00%
RegExp Creation (Execution) 11.6±0.33µs 11.9±0.57µs +2.59%
RegExp Creation (Parser) 14.1±1.05µs 13.9±0.57µs -1.42%
RegExp Literal (Compiler) 2.7±0.13µs 2.7±0.10µs 0.00%
RegExp Literal (Execution) 16.9±0.72µs 18.5±1.92µs +9.47%
RegExp Literal (Parser) 18.1±0.87µs 18.4±0.57µs +1.66%
RegExp Literal Creation (Compiler) 2.4±0.11µs 2.4±0.14µs 0.00%
RegExp Literal Creation (Execution) 11.7±0.74µs 12.2±0.80µs +4.27%
RegExp Literal Creation (Parser) 15.1±1.03µs 15.5±0.77µs +2.65%
Static Object Property Access (Compiler) 2.4±0.13µs 2.5±0.27µs +4.17%
Static Object Property Access (Execution) 6.6±0.38µs 6.4±0.39µs -3.03%
Static Object Property Access (Parser) 16.1±0.57µs 16.7±1.24µs +3.73%
String Object Access (Compiler) 2.1±0.11µs 2.1±0.08µs 0.00%
String Object Access (Execution) 7.9±0.26µs 7.9±0.43µs 0.00%
String Object Access (Parser) 23.2±3.57µs 23.0±0.78µs -0.86%
String comparison (Compiler) 3.4±0.13µs 3.5±0.19µs +2.94%
String comparison (Execution) 5.6±0.43µs 5.8±1.59µs +3.57%
String comparison (Parser) 18.2±1.01µs 18.1±0.63µs -0.55%
String concatenation (Compiler) 2.8±0.37µs 2.8±0.26µs 0.00%
String concatenation (Execution) 5.4±0.39µs 5.3±0.35µs -1.85%
String concatenation (Parser) 12.3±0.60µs 12.5±0.63µs +1.63%
String copy (Compiler) 2.2±0.11µs 2.3±0.16µs +4.55%
String copy (Execution) 5.0±0.23µs 5.0±0.43µs 0.00%
String copy (Parser) 9.4±0.59µs 9.5±0.74µs +1.06%
Symbols (Compiler) 1680.4±113.41ns 1695.1±73.59ns +0.87%
Symbols (Execution) 5.0±0.32µs 5.1±0.28µs +2.00%
Symbols (Parser) 7.2±0.43µs 7.4±0.32µs +2.78%

@HalidOdat HalidOdat force-pushed the optimization/constant-folding branch from d451d75 to 0f07439 Compare March 18, 2023 22:43
@HalidOdat HalidOdat marked this pull request as ready for review March 18, 2023 22:43
@HalidOdat
Copy link
Member Author

This is now ready for review/merge :) 🎉

Also implemented statistics for optimizations which will be printed with the --optimizer-statistics, right now only tracking how many times a it ran and how many passes where in total, will be more interesting when we implement other optimizations.

cargo run -- -O --optimizer-statistics
>>> (1 + 2 * 3) + '00'
Optimizer {
    constant folding: 1 run(s), 2 pass(es) (1 mutating, 1 checking)
}

@github-actions
Copy link

Benchmark for 7c6bab0

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 535.7±26.43ns 346.2±13.47ns -35.37%
Arithmetic operations (Execution) 443.2±18.70ns 89.2±4.14ns -79.87%
Arithmetic operations (Parser) 6.2±0.30µs 6.8±0.42µs +9.68%
Array access (Compiler) 1519.4±76.78ns 1547.3±93.86ns +1.84%
Array access (Execution) 8.0±0.36µs 6.8±0.32µs -15.00%
Array access (Parser) 13.0±0.67µs 14.5±0.85µs +11.54%
Array creation (Compiler) 2.4±0.15µs 2.2±0.12µs -8.33%
Array creation (Execution) 1132.4±74.60µs 1021.7±47.46µs -9.78%
Array creation (Parser) 15.8±0.78µs 16.3±0.86µs +3.16%
Array pop (Compiler) 4.3±0.21µs 4.0±0.18µs -6.98%
Array pop (Execution) 596.9±43.36µs 581.8±28.51µs -2.53%
Array pop (Parser) 139.7±7.60µs 154.6±12.50µs +10.67%
Boolean Object Access (Compiler) 1245.6±36.24ns 1132.3±96.87ns -9.10%
Boolean Object Access (Execution) 3.9±0.20µs 4.0±0.22µs +2.56%
Boolean Object Access (Parser) 17.0±0.83µs 19.4±0.72µs +14.12%
Clean js (Compiler) 4.7±0.26µs 4.6±0.25µs -2.13%
Clean js (Execution) 593.2±37.91µs 603.6±31.08µs +1.75%
Clean js (Parser) 33.4±1.59µs 33.4±1.71µs 0.00%
Create Realm 426.0±27.26µs 422.8±18.07µs -0.75%
Dynamic Object Property Access (Compiler) 1891.8±92.86ns 1800.4±101.11ns -4.83%
Dynamic Object Property Access (Execution) 4.6±0.30µs 4.3±0.25µs -6.52%
Dynamic Object Property Access (Parser) 11.8±0.70µs 12.2±0.53µs +3.39%
Fibonacci (Compiler) 3.2±0.09µs 2.8±0.15µs -12.50%
Fibonacci (Execution) 956.0±39.32µs 978.0±45.01µs +2.30%
Fibonacci (Parser) 20.3±1.87µs 18.7±0.84µs -7.88%
For loop (Compiler) 2.9±0.14µs 2.5±0.12µs -13.79%
For loop (Execution) 14.4±0.61µs 15.1±0.87µs +4.86%
For loop (Parser) 17.8±1.21µs 16.6±0.88µs -6.74%
Mini js (Compiler) 4.1±0.24µs 4.1±0.21µs 0.00%
Mini js (Execution) 554.0±32.58µs 547.8±32.66µs -1.12%
Mini js (Parser) 29.1±1.09µs 28.8±1.44µs -1.03%
Number Object Access (Compiler) 1111.0±76.51ns 1193.7±41.60ns +7.44%
Number Object Access (Execution) 3.1±0.18µs 3.1±0.15µs 0.00%
Number Object Access (Parser) 13.1±0.69µs 14.4±0.78µs +9.92%
Object Creation (Compiler) 1810.5±127.36ns 1677.8±100.18ns -7.33%
Object Creation (Execution) 4.2±0.23µs 4.1±0.24µs -2.38%
Object Creation (Parser) 10.4±0.60µs 10.0±0.46µs -3.85%
RegExp (Compiler) 1844.9±82.11ns 1836.8±98.14ns -0.44%
RegExp (Execution) 12.0±0.96µs 11.2±0.64µs -6.67%
RegExp (Parser) 11.5±0.53µs 11.8±0.68µs +2.61%
RegExp Creation (Compiler) 1619.9±68.74ns 1585.5±84.30ns -2.12%
RegExp Creation (Execution) 8.1±0.44µs 7.9±0.41µs -2.47%
RegExp Creation (Parser) 10.2±0.64µs 9.7±0.42µs -4.90%
RegExp Literal (Compiler) 1828.6±74.04ns 1799.7±84.57ns -1.58%
RegExp Literal (Execution) 11.5±0.72µs 11.5±0.74µs 0.00%
RegExp Literal (Parser) 12.7±0.70µs 12.8±0.54µs +0.79%
RegExp Literal Creation (Compiler) 1750.0±111.66ns 1688.9±116.78ns -3.49%
RegExp Literal Creation (Execution) 8.3±0.43µs 8.1±0.46µs -2.41%
RegExp Literal Creation (Parser) 12.0±0.52µs 11.2±0.57µs -6.67%
Static Object Property Access (Compiler) 1689.1±97.40ns 1677.0±97.43ns -0.72%
Static Object Property Access (Execution) 4.6±0.26µs 4.0±0.16µs -13.04%
Static Object Property Access (Parser) 11.6±0.78µs 11.3±0.68µs -2.59%
String Object Access (Compiler) 1384.4±79.72ns 1400.1±61.21ns +1.13%
String Object Access (Execution) 5.2±0.21µs 5.6±0.30µs +7.69%
String Object Access (Parser) 16.3±0.98µs 16.1±0.89µs -1.23%
String comparison (Compiler) 2.4±0.16µs 2.4±0.16µs 0.00%
String comparison (Execution) 3.9±0.22µs 3.9±0.17µs 0.00%
String comparison (Parser) 13.5±0.55µs 14.1±0.84µs +4.44%
String concatenation (Compiler) 1904.2±118.95ns 1835.5±85.15ns -3.61%
String concatenation (Execution) 3.6±0.19µs 3.6±0.16µs 0.00%
String concatenation (Parser) 8.6±0.41µs 8.9±0.42µs +3.49%
String copy (Compiler) 1636.0±106.14ns 1736.8±84.82ns +6.16%
String copy (Execution) 3.4±0.18µs 3.3±0.21µs -2.94%
String copy (Parser) 6.7±0.35µs 7.5±0.35µs +11.94%
Symbols (Compiler) 1232.7±70.55ns 1142.3±58.25ns -7.33%
Symbols (Execution) 3.4±0.17µs 3.3±0.15µs -2.94%
Symbols (Parser) 5.5±0.28µs 5.1±0.32µs -7.27%

@HalidOdat HalidOdat added this to the v0.17.0 milestone Mar 18, 2023
@HalidOdat HalidOdat requested review from nekevss and RageKnify March 18, 2023 23:37
@github-actions
Copy link

Benchmark for da43591

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 708.5±26.86ns 497.0±45.81ns -29.85%
Arithmetic operations (Execution) 566.9±31.72ns 108.2±7.07ns -80.91%
Arithmetic operations (Parser) 8.4±0.57µs 8.8±0.52µs +4.76%
Array access (Compiler) 2.1±0.15µs 2.1±0.14µs 0.00%
Array access (Execution) 9.5±0.41µs 9.6±0.50µs +1.05%
Array access (Parser) 17.0±1.21µs 18.9±0.81µs +11.18%
Array creation (Compiler) 3.1±0.17µs 3.0±0.19µs -3.23%
Array creation (Execution) 1224.3±59.75µs 1234.0±54.13µs +0.79%
Array creation (Parser) 20.9±1.27µs 23.6±1.58µs +12.92%
Array pop (Compiler) 5.0±0.33µs 5.1±0.24µs +2.00%
Array pop (Execution) 731.0±51.07µs 718.6±44.73µs -1.70%
Array pop (Parser) 182.2±12.00µs 199.4±6.76µs +9.44%
Boolean Object Access (Compiler) 1452.3±73.90ns 1505.0±87.19ns +3.63%
Boolean Object Access (Execution) 5.5±0.20µs 5.2±0.34µs -5.45%
Boolean Object Access (Parser) 21.9±1.41µs 22.7±1.41µs +3.65%
Clean js (Compiler) 6.4±0.28µs 6.5±0.28µs +1.56%
Clean js (Execution) 767.5±39.27µs 756.3±42.18µs -1.46%
Clean js (Parser) 44.9±2.94µs 44.2±3.86µs -1.56%
Create Realm 583.5±25.83µs 583.3±36.04µs -0.03%
Dynamic Object Property Access (Compiler) 2.4±0.13µs 2.4±0.17µs 0.00%
Dynamic Object Property Access (Execution) 6.3±0.30µs 6.1±0.64µs -3.17%
Dynamic Object Property Access (Parser) 15.7±1.03µs 18.2±0.91µs +15.92%
Fibonacci (Compiler) 3.8±0.21µs 3.8±0.18µs 0.00%
Fibonacci (Execution) 1396.2±99.46µs 1381.7±68.05µs -1.04%
Fibonacci (Parser) 25.5±1.51µs 26.6±1.67µs +4.31%
For loop (Compiler) 3.5±0.26µs 3.5±0.17µs 0.00%
For loop (Execution) 20.6±1.06µs 19.9±1.06µs -3.40%
For loop (Parser) 22.5±1.87µs 22.3±1.12µs -0.89%
Mini js (Compiler) 5.7±0.25µs 5.6±0.37µs -1.75%
Mini js (Execution) 693.3±93.97µs 677.7±36.36µs -2.25%
Mini js (Parser) 38.6±2.17µs 39.0±2.51µs +1.04%
Number Object Access (Compiler) 1376.2±86.47ns 1413.3±66.18ns +2.70%
Number Object Access (Execution) 4.3±0.11µs 4.3±0.43µs 0.00%
Number Object Access (Parser) 16.2±1.00µs 17.2±0.78µs +6.17%
Object Creation (Compiler) 2.3±0.09µs 2.2±0.12µs -4.35%
Object Creation (Execution) 5.9±0.22µs 5.9±0.14µs 0.00%
Object Creation (Parser) 14.2±0.90µs 15.1±0.71µs +6.34%
RegExp (Compiler) 2.5±0.11µs 2.6±0.18µs +4.00%
RegExp (Execution) 15.8±0.60µs 16.3±0.76µs +3.16%
RegExp (Parser) 15.2±1.14µs 16.0±0.86µs +5.26%
RegExp Creation (Compiler) 2.2±0.07µs 2.2±0.13µs 0.00%
RegExp Creation (Execution) 10.9±0.57µs 10.6±0.63µs -2.75%
RegExp Creation (Parser) 12.7±0.72µs 13.9±0.52µs +9.45%
RegExp Literal (Compiler) 2.5±0.09µs 2.6±0.19µs +4.00%
RegExp Literal (Execution) 15.7±0.96µs 16.7±0.84µs +6.37%
RegExp Literal (Parser) 17.2±1.75µs 18.3±1.12µs +6.40%
RegExp Literal Creation (Compiler) 2.3±0.14µs 2.3±0.11µs 0.00%
RegExp Literal Creation (Execution) 10.9±0.57µs 11.1±0.71µs +1.83%
RegExp Literal Creation (Parser) 14.3±0.74µs 15.5±0.77µs +8.39%
Static Object Property Access (Compiler) 2.3±0.11µs 2.3±0.13µs 0.00%
Static Object Property Access (Execution) 6.0±0.24µs 6.1±0.19µs +1.67%
Static Object Property Access (Parser) 14.9±1.02µs 15.7±0.82µs +5.37%
String Object Access (Compiler) 1866.9±111.80ns 1943.3±87.45ns +4.09%
String Object Access (Execution) 7.8±0.44µs 7.3±0.43µs -6.41%
String Object Access (Parser) 21.3±1.21µs 21.8±1.84µs +2.35%
String comparison (Compiler) 3.1±0.12µs 3.2±0.17µs +3.23%
String comparison (Execution) 5.5±0.36µs 5.3±0.36µs -3.64%
String comparison (Parser) 16.4±1.32µs 17.6±0.62µs +7.32%
String concatenation (Compiler) 2.5±0.12µs 2.6±0.14µs +4.00%
String concatenation (Execution) 4.9±0.26µs 4.9±0.27µs 0.00%
String concatenation (Parser) 11.6±0.55µs 12.3±0.38µs +6.03%
String copy (Compiler) 2.1±0.07µs 2.2±0.15µs +4.76%
String copy (Execution) 4.8±0.17µs 4.7±0.27µs -2.08%
String copy (Parser) 8.1±0.51µs 8.9±0.53µs +9.88%
Symbols (Compiler) 1509.1±84.75ns 1510.6±116.94ns +0.10%
Symbols (Execution) 4.8±0.47µs 4.5±0.28µs -6.25%
Symbols (Parser) 7.0±0.34µs 7.1±0.31µs +1.43%

Copy link
Member

@raskad raskad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!
We should definitely adjust our ci and tests for optimized / unoptimized code, but I would say lets merge this.

Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good overall! Just a couple comments. 😄

boa_ast/src/expression/literal/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/context/mod.rs Outdated Show resolved Hide resolved
@github-actions
Copy link

Benchmark for 46ebdbd

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 682.4±2.07ns 659.0±7.06ns -3.43%
Arithmetic operations (Execution) 561.4±5.36ns 611.6±13.21ns +8.94%
Arithmetic operations (Parser) 7.7±0.05µs 7.6±0.10µs -1.30%
Array access (Compiler) 1967.8±18.50ns 1943.4±7.45ns -1.24%
Array access (Execution) 8.6±0.16µs 8.5±0.20µs -1.16%
Array access (Parser) 16.0±0.11µs 15.9±0.15µs -0.62%
Array creation (Compiler) 2.9±0.04µs 2.8±0.01µs -3.45%
Array creation (Execution) 1281.5±8.19µs 1269.0±6.56µs -0.98%
Array creation (Parser) 19.4±0.08µs 19.3±0.16µs -0.52%
Array pop (Compiler) 5.4±0.06µs 5.2±0.03µs -3.70%
Array pop (Execution) 733.1±11.96µs 716.7±2.36µs -2.24%
Array pop (Parser) 175.1±0.79µs 174.1±0.52µs -0.57%
Boolean Object Access (Compiler) 1351.2±9.30ns 1323.6±8.04ns -2.04%
Boolean Object Access (Execution) 5.0±0.02µs 4.9±0.01µs -2.00%
Boolean Object Access (Parser) 20.3±0.08µs 20.3±0.31µs 0.00%
Clean js (Compiler) 5.7±0.05µs 5.7±0.04µs 0.00%
Clean js (Execution) 721.5±3.69µs 718.7±10.14µs -0.39%
Clean js (Parser) 41.0±0.32µs 40.6±0.27µs -0.98%
Create Realm 518.3±4.42µs 514.9±6.85µs -0.66%
Dynamic Object Property Access (Compiler) 2.4±0.07µs 2.3±0.01µs -4.17%
Dynamic Object Property Access (Execution) 5.5±0.03µs 5.4±0.10µs -1.82%
Dynamic Object Property Access (Parser) 14.2±0.07µs 14.1±0.05µs -0.70%
Fibonacci (Compiler) 3.5±0.04µs 3.4±0.05µs -2.86%
Fibonacci (Execution) 1209.8±10.35µs 1197.7±11.54µs -1.00%
Fibonacci (Parser) 23.0±0.34µs 23.0±0.18µs 0.00%
For loop (Compiler) 3.2±0.03µs 3.2±0.03µs 0.00%
For loop (Execution) 19.6±0.24µs 20.1±0.12µs +2.55%
For loop (Parser) 19.9±0.17µs 20.0±0.16µs +0.50%
Mini js (Compiler) 5.1±0.07µs 5.1±0.08µs 0.00%
Mini js (Execution) 664.5±3.93µs 658.6±8.36µs -0.89%
Mini js (Parser) 35.6±0.45µs 35.3±0.40µs -0.84%
Number Object Access (Compiler) 1285.2±9.65ns 1271.9±1.60ns -1.03%
Number Object Access (Execution) 3.8±0.02µs 3.8±0.09µs 0.00%
Number Object Access (Parser) 15.4±0.09µs 15.4±0.08µs 0.00%
Object Creation (Compiler) 2.1±0.01µs 2.0±0.02µs -4.76%
Object Creation (Execution) 5.1±0.02µs 5.1±0.12µs 0.00%
Object Creation (Parser) 12.6±0.08µs 12.5±0.06µs -0.79%
RegExp (Compiler) 2.4±0.01µs 2.3±0.02µs -4.17%
RegExp (Execution) 14.4±0.07µs 13.7±0.15µs -4.86%
RegExp (Parser) 13.8±0.14µs 13.7±0.10µs -0.72%
RegExp Creation (Compiler) 2.1±0.01µs 2.0±0.02µs -4.76%
RegExp Creation (Execution) 10.2±0.09µs 9.7±0.11µs -4.90%
RegExp Creation (Parser) 11.5±0.08µs 11.5±0.25µs 0.00%
RegExp Literal (Compiler) 2.4±0.01µs 2.3±0.02µs -4.17%
RegExp Literal (Execution) 14.3±0.20µs 13.7±0.25µs -4.20%
RegExp Literal (Parser) 15.4±0.23µs 15.1±0.40µs -1.95%
RegExp Literal Creation (Compiler) 2.1±0.03µs 2.0±0.01µs -4.76%
RegExp Literal Creation (Execution) 10.1±0.08µs 9.7±0.07µs -3.96%
RegExp Literal Creation (Parser) 13.3±0.03µs 13.0±0.07µs -2.26%
Static Object Property Access (Compiler) 2.2±0.02µs 2.1±0.02µs -4.55%
Static Object Property Access (Execution) 5.3±0.02µs 5.2±0.08µs -1.89%
Static Object Property Access (Parser) 13.5±0.06µs 13.5±0.10µs 0.00%
String Object Access (Compiler) 1803.2±23.97ns 1721.8±14.19ns -4.51%
String Object Access (Execution) 6.8±0.07µs 6.8±0.05µs 0.00%
String Object Access (Parser) 19.6±0.13µs 19.3±0.22µs -1.53%
String comparison (Compiler) 3.0±0.03µs 2.9±0.04µs -3.33%
String comparison (Execution) 4.7±0.06µs 4.6±0.03µs -2.13%
String comparison (Parser) 15.6±0.08µs 15.4±0.25µs -1.28%
String concatenation (Compiler) 2.4±0.02µs 2.3±0.03µs -4.17%
String concatenation (Execution) 4.4±0.03µs 4.4±0.06µs 0.00%
String concatenation (Parser) 10.6±0.06µs 10.5±0.02µs -0.94%
String copy (Compiler) 1971.8±20.90ns 1898.9±13.52ns -3.70%
String copy (Execution) 4.2±0.02µs 4.0±0.03µs -4.76%
String copy (Parser) 7.8±0.07µs 7.7±0.04µs -1.28%
Symbols (Compiler) 1476.4±22.55ns 1376.1±34.90ns -6.79%
Symbols (Execution) 4.3±0.03µs 4.1±0.05µs -4.65%
Symbols (Parser) 6.0±0.07µs 6.0±0.02µs 0.00%

@github-actions
Copy link

Benchmark for ccf84f4

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 697.9±53.69ns 727.5±63.78ns +4.24%
Arithmetic operations (Execution) 478.3±28.15ns 521.8±33.39ns +9.09%
Arithmetic operations (Parser) 7.3±0.42µs 7.5±0.64µs +2.74%
Array access (Compiler) 1940.0±121.56ns 1963.4±135.13ns +1.21%
Array access (Execution) 8.3±0.72µs 8.3±0.50µs 0.00%
Array access (Parser) 15.5±1.01µs 15.6±1.86µs +0.65%
Array creation (Compiler) 2.9±0.22µs 2.9±0.18µs 0.00%
Array creation (Execution) 1150.8±146.53µs 1133.1±91.04µs -1.54%
Array creation (Parser) 18.6±1.20µs 18.8±1.28µs +1.08%
Array pop (Compiler) 5.0±0.29µs 4.9±0.32µs -2.00%
Array pop (Execution) 680.8±74.90µs 647.3±45.12µs -4.92%
Array pop (Parser) 166.6±11.53µs 168.8±11.92µs +1.32%
Boolean Object Access (Compiler) 1343.1±95.41ns 1431.3±93.88ns +6.57%
Boolean Object Access (Execution) 4.9±0.30µs 4.6±0.28µs -6.12%
Boolean Object Access (Parser) 19.0±0.97µs 19.5±2.03µs +2.63%
Clean js (Compiler) 5.8±0.40µs 6.0±0.40µs +3.45%
Clean js (Execution) 652.5±38.20µs 761.4±59.16µs +16.69%
Clean js (Parser) 40.5±2.98µs 40.6±3.42µs +0.25%
Create Realm 493.0±33.64µs 501.8±39.28µs +1.78%
Dynamic Object Property Access (Compiler) 2.3±0.21µs 2.4±0.16µs +4.35%
Dynamic Object Property Access (Execution) 5.4±0.33µs 5.7±0.51µs +5.56%
Dynamic Object Property Access (Parser) 14.0±1.06µs 15.2±1.25µs +8.57%
Fibonacci (Compiler) 3.5±0.26µs 3.6±0.20µs +2.86%
Fibonacci (Execution) 1275.3±71.52µs 1299.1±118.52µs +1.87%
Fibonacci (Parser) 22.4±1.50µs 23.0±2.14µs +2.68%
For loop (Compiler) 3.3±0.21µs 3.3±0.19µs 0.00%
For loop (Execution) 19.9±1.23µs 20.0±1.27µs +0.50%
For loop (Parser) 19.4±1.14µs 19.1±1.32µs -1.55%
Mini js (Compiler) 5.2±0.33µs 5.3±0.35µs +1.92%
Mini js (Execution) 593.9±56.59µs 666.3±29.10µs +12.19%
Mini js (Parser) 34.5±2.45µs 35.1±2.18µs +1.74%
Number Object Access (Compiler) 1253.0±74.74ns 1343.8±106.73ns +7.25%
Number Object Access (Execution) 3.8±0.26µs 3.6±0.19µs -5.26%
Number Object Access (Parser) 14.6±1.02µs 14.9±0.88µs +2.05%
Object Creation (Compiler) 2.2±0.20µs 2.1±0.12µs -4.55%
Object Creation (Execution) 5.2±0.33µs 5.3±0.41µs +1.92%
Object Creation (Parser) 12.1±0.93µs 13.1±1.41µs +8.26%
RegExp (Compiler) 2.3±0.12µs 2.4±0.12µs +4.35%
RegExp (Execution) 14.8±1.46µs 14.6±0.69µs -1.35%
RegExp (Parser) 13.1±0.77µs 13.6±1.33µs +3.82%
RegExp Creation (Compiler) 2.0±0.12µs 2.1±0.12µs +5.00%
RegExp Creation (Execution) 10.2±0.92µs 9.9±0.78µs -2.94%
RegExp Creation (Parser) 11.6±0.88µs 11.6±2.25µs 0.00%
RegExp Literal (Compiler) 2.2±0.13µs 2.4±0.14µs +9.09%
RegExp Literal (Execution) 15.2±2.11µs 14.9±0.99µs -1.97%
RegExp Literal (Parser) 14.9±1.03µs 16.2±1.44µs +8.72%
RegExp Literal Creation (Compiler) 2.1±0.14µs 2.1±0.11µs 0.00%
RegExp Literal Creation (Execution) 10.0±1.53µs 9.8±0.64µs -2.00%
RegExp Literal Creation (Parser) 12.5±0.73µs 12.9±0.98µs +3.20%
Static Object Property Access (Compiler) 2.1±0.14µs 2.2±0.11µs +4.76%
Static Object Property Access (Execution) 5.4±0.35µs 5.6±0.96µs +3.70%
Static Object Property Access (Parser) 13.2±1.13µs 14.2±1.07µs +7.58%
String Object Access (Compiler) 1747.1±351.58ns 1754.2±119.34ns +0.41%
String Object Access (Execution) 7.1±1.62µs 6.6±0.44µs -7.04%
String Object Access (Parser) 19.3±2.11µs 18.0±1.00µs -6.74%
String comparison (Compiler) 2.8±0.15µs 3.1±0.23µs +10.71%
String comparison (Execution) 4.8±0.34µs 4.7±0.31µs -2.08%
String comparison (Parser) 15.4±1.15µs 14.9±1.27µs -3.25%
String concatenation (Compiler) 2.3±0.23µs 2.4±0.15µs +4.35%
String concatenation (Execution) 4.5±0.30µs 4.5±0.34µs 0.00%
String concatenation (Parser) 10.3±0.69µs 10.3±1.17µs 0.00%
String copy (Compiler) 1933.9±109.86ns 2.1±0.12µs +8.59%
String copy (Execution) 4.2±0.55µs 4.3±0.32µs +2.38%
String copy (Parser) 8.2±0.76µs 7.9±0.57µs -3.66%
Symbols (Compiler) 1430.6±97.94ns 1496.7±103.37ns +4.62%
Symbols (Execution) 4.2±0.22µs 4.2±0.23µs 0.00%
Symbols (Parser) 5.9±0.41µs 6.1±0.41µs +3.39%

@github-actions
Copy link

Benchmark for 6827dd9

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 566.7±0.62ns 543.9±0.76ns -4.02%
Arithmetic operations (Execution) 414.7±1.19ns 488.7±0.21ns +17.84%
Arithmetic operations (Parser) 7.4±0.02µs 7.3±0.06µs -1.35%
Array access (Compiler) 1710.4±3.42ns 1674.4±4.24ns -2.10%
Array access (Execution) 7.7±0.02µs 7.6±0.02µs -1.30%
Array access (Parser) 16.1±0.05µs 16.1±0.38µs 0.00%
Array creation (Compiler) 2.5±0.00µs 2.5±0.07µs 0.00%
Array creation (Execution) 1118.4±1.63µs 1115.4±1.05µs -0.27%
Array creation (Parser) 18.8±0.04µs 19.3±0.05µs +2.66%
Array pop (Compiler) 4.4±0.01µs 4.2±0.01µs -4.55%
Array pop (Execution) 637.2±0.99µs 643.0±1.06µs +0.91%
Array pop (Parser) 161.4±1.72µs 163.3±0.13µs +1.18%
Boolean Object Access (Compiler) 1198.6±4.10ns 1177.6±2.50ns -1.75%
Boolean Object Access (Execution) 4.6±0.01µs 4.4±0.01µs -4.35%
Boolean Object Access (Parser) 19.4±0.04µs 19.4±0.04µs 0.00%
Clean js (Compiler) 5.2±0.01µs 5.2±0.01µs 0.00%
Clean js (Execution) 637.3±5.04µs 635.7±3.02µs -0.25%
Clean js (Parser) 39.8±0.09µs 40.0±0.10µs +0.50%
Create Realm 427.9±3.05µs 424.8±3.05µs -0.72%
Dynamic Object Property Access (Compiler) 2.1±0.02µs 1965.8±3.81ns -6.39%
Dynamic Object Property Access (Execution) 4.9±0.01µs 4.9±0.02µs 0.00%
Dynamic Object Property Access (Parser) 14.5±0.28µs 14.3±0.04µs -1.38%
Fibonacci (Compiler) 3.1±0.01µs 3.1±0.02µs 0.00%
Fibonacci (Execution) 1093.8±11.35µs 1096.6±9.65µs +0.26%
Fibonacci (Parser) 22.5±0.04µs 22.8±0.06µs +1.33%
For loop (Compiler) 2.9±0.02µs 2.8±0.02µs -3.45%
For loop (Execution) 17.1±0.04µs 17.4±0.26µs +1.75%
For loop (Parser) 19.2±0.04µs 19.3±0.05µs +0.52%
Mini js (Compiler) 4.5±0.01µs 4.6±0.01µs +2.22%
Mini js (Execution) 581.8±2.38µs 587.1±2.42µs +0.91%
Mini js (Parser) 35.0±0.07µs 34.9±0.09µs -0.29%
Number Object Access (Compiler) 1104.4±6.97ns 1096.1±2.89ns -0.75%
Number Object Access (Execution) 3.5±0.01µs 3.5±0.06µs 0.00%
Number Object Access (Parser) 15.0±0.07µs 15.0±0.03µs 0.00%
Object Creation (Compiler) 1860.2±19.96ns 1744.4±6.56ns -6.23%
Object Creation (Execution) 4.7±0.08µs 4.6±0.02µs -2.13%
Object Creation (Parser) 12.6±0.05µs 12.7±0.12µs +0.79%
RegExp (Compiler) 2.3±0.01µs 1994.7±5.98ns -13.27%
RegExp (Execution) 12.3±0.02µs 12.2±0.03µs -0.81%
RegExp (Parser) 13.6±0.04µs 13.7±0.27µs +0.74%
RegExp Creation (Compiler) 1976.8±28.17ns 1771.4±2.97ns -10.39%
RegExp Creation (Execution) 8.8±0.02µs 8.7±0.03µs -1.14%
RegExp Creation (Parser) 11.4±0.04µs 11.5±0.06µs +0.88%
RegExp Literal (Compiler) 2.2±0.03µs 1993.4±4.07ns -9.39%
RegExp Literal (Execution) 12.3±0.03µs 12.3±0.03µs 0.00%
RegExp Literal (Parser) 14.7±0.02µs 14.8±0.03µs +0.68%
RegExp Literal Creation (Compiler) 1966.2±38.24ns 1771.4±2.79ns -9.91%
RegExp Literal Creation (Execution) 8.8±0.04µs 8.8±0.06µs 0.00%
RegExp Literal Creation (Parser) 12.4±0.07µs 12.6±0.03µs +1.61%
Static Object Property Access (Compiler) 1810.3±8.02ns 1761.9±12.25ns -2.67%
Static Object Property Access (Execution) 4.8±0.01µs 4.7±0.01µs -2.08%
Static Object Property Access (Parser) 13.5±0.05µs 13.5±0.04µs 0.00%
String Object Access (Compiler) 1548.8±4.60ns 1520.8±2.70ns -1.81%
String Object Access (Execution) 6.1±0.03µs 6.1±0.03µs 0.00%
String Object Access (Parser) 18.8±0.02µs 18.9±0.04µs +0.53%
String comparison (Compiler) 2.6±0.01µs 2.6±0.00µs 0.00%
String comparison (Execution) 4.1±0.01µs 4.1±0.03µs 0.00%
String comparison (Parser) 15.4±0.02µs 15.5±0.03µs +0.65%
String concatenation (Compiler) 2.1±0.01µs 2.0±0.00µs -4.76%
String concatenation (Execution) 3.8±0.01µs 3.9±0.02µs +2.63%
String concatenation (Parser) 10.5±0.02µs 10.5±0.03µs 0.00%
String copy (Compiler) 1774.7±14.41ns 1648.5±3.61ns -7.11%
String copy (Execution) 3.7±0.01µs 3.6±0.03µs -2.70%
String copy (Parser) 8.1±0.02µs 8.1±0.02µs 0.00%
Symbols (Compiler) 1244.6±3.35ns 1212.0±25.23ns -2.62%
Symbols (Execution) 3.7±0.02µs 3.7±0.03µs 0.00%
Symbols (Parser) 6.3±0.02µs 6.3±0.04µs 0.00%

@HalidOdat HalidOdat requested a review from nekevss March 20, 2023 21:05
@github-actions
Copy link

Benchmark for 66f8dc5

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 501.5±0.44ns 492.4±0.73ns -1.81%
Arithmetic operations (Execution) 419.6±0.23ns 512.8±0.19ns +22.21%
Arithmetic operations (Parser) 6.1±0.12µs 6.1±0.02µs 0.00%
Array access (Compiler) 1433.2±2.25ns 1641.4±5.19ns +14.53%
Array access (Execution) 6.4±0.02µs 6.3±0.02µs -1.56%
Array access (Parser) 12.8±0.02µs 12.8±0.02µs 0.00%
Array creation (Compiler) 2.1±0.01µs 2.3±0.00µs +9.52%
Array creation (Execution) 952.4±8.49µs 896.7±1.44µs -5.85%
Array creation (Parser) 15.4±0.02µs 15.3±0.01µs -0.65%
Array pop (Compiler) 4.0±0.01µs 4.2±0.01µs +5.00%
Array pop (Execution) 539.8±0.80µs 518.0±0.84µs -4.04%
Array pop (Parser) 136.3±0.15µs 154.5±0.21µs +13.35%
Boolean Object Access (Compiler) 1056.4±1.57ns 1067.5±1.89ns +1.05%
Boolean Object Access (Execution) 3.7±0.00µs 3.6±0.00µs -2.70%
Boolean Object Access (Parser) 16.0±0.09µs 17.9±0.03µs +11.87%
Clean js (Compiler) 4.3±0.01µs 4.2±0.01µs -2.33%
Clean js (Execution) 536.3±2.17µs 528.1±1.80µs -1.53%
Clean js (Parser) 32.7±0.04µs 32.1±0.03µs -1.83%
Create Realm 378.1±0.80µs 428.6±0.92µs +13.36%
Dynamic Object Property Access (Compiler) 1751.4±2.90ns 1700.5±3.28ns -2.91%
Dynamic Object Property Access (Execution) 4.0±0.01µs 4.0±0.01µs 0.00%
Dynamic Object Property Access (Parser) 11.5±0.01µs 11.4±0.02µs -0.87%
Fibonacci (Compiler) 2.6±0.01µs 2.6±0.01µs 0.00%
Fibonacci (Execution) 902.2±2.58µs 902.3±1.35µs +0.01%
Fibonacci (Parser) 18.3±0.04µs 18.4±0.19µs +0.55%
For loop (Compiler) 2.4±0.00µs 2.4±0.00µs 0.00%
For loop (Execution) 14.6±0.04µs 14.5±0.07µs -0.68%
For loop (Parser) 15.9±0.08µs 18.0±0.03µs +13.21%
Mini js (Compiler) 3.8±0.00µs 3.8±0.00µs 0.00%
Mini js (Execution) 493.2±1.55µs 489.6±1.92µs -0.73%
Mini js (Parser) 28.5±0.04µs 28.3±0.03µs -0.70%
Number Object Access (Compiler) 992.2±1.08ns 991.4±2.48ns -0.08%
Number Object Access (Execution) 2.9±0.04µs 2.8±0.00µs -3.45%
Number Object Access (Parser) 12.2±0.02µs 13.8±0.03µs +13.11%
Object Creation (Compiler) 1586.4±11.53ns 1523.3±1.72ns -3.98%
Object Creation (Execution) 3.8±0.01µs 3.7±0.00µs -2.63%
Object Creation (Parser) 10.2±0.02µs 11.3±0.02µs +10.78%
RegExp (Compiler) 1761.7±1.80ns 1928.1±5.34ns +9.45%
RegExp (Execution) 10.7±0.04µs 10.9±0.03µs +1.87%
RegExp (Parser) 11.0±0.02µs 11.0±0.03µs 0.00%
RegExp Creation (Compiler) 1556.1±2.41ns 1516.4±3.45ns -2.55%
RegExp Creation (Execution) 7.6±0.02µs 7.6±0.03µs 0.00%
RegExp Creation (Parser) 9.3±0.01µs 9.3±0.02µs 0.00%
RegExp Literal (Compiler) 1774.1±2.80ns 1939.9±5.55ns +9.35%
RegExp Literal (Execution) 10.6±0.01µs 10.9±0.03µs +2.83%
RegExp Literal (Parser) 12.2±0.02µs 12.2±0.01µs 0.00%
RegExp Literal Creation (Compiler) 1556.8±3.04ns 1511.9±4.08ns -2.88%
RegExp Literal Creation (Execution) 7.6±0.02µs 7.5±0.01µs -1.32%
RegExp Literal Creation (Parser) 10.4±0.01µs 10.4±0.03µs 0.00%
Static Object Property Access (Compiler) 1546.1±1.74ns 1537.6±2.66ns -0.55%
Static Object Property Access (Execution) 3.9±0.01µs 3.8±0.07µs -2.56%
Static Object Property Access (Parser) 11.0±0.01µs 12.2±0.03µs +10.91%
String Object Access (Compiler) 1329.3±2.06ns 1329.9±3.24ns +0.05%
String Object Access (Execution) 5.0±0.01µs 5.0±0.01µs 0.00%
String Object Access (Parser) 15.3±0.02µs 17.3±0.04µs +13.07%
String comparison (Compiler) 2.2±0.00µs 2.4±0.00µs +9.09%
String comparison (Execution) 3.5±0.01µs 3.4±0.01µs -2.86%
String comparison (Parser) 12.4±0.01µs 14.0±0.07µs +12.90%
String concatenation (Compiler) 1748.7±2.50ns 1960.2±3.32ns +12.09%
String concatenation (Execution) 3.2±0.01µs 3.2±0.01µs 0.00%
String concatenation (Parser) 8.5±0.02µs 9.6±0.02µs +12.94%
String copy (Compiler) 1442.7±2.70ns 1426.9±3.31ns -1.10%
String copy (Execution) 3.1±0.01µs 3.0±0.01µs -3.23%
String copy (Parser) 6.3±0.01µs 7.2±0.02µs +14.29%
Symbols (Compiler) 1045.3±1.76ns 1046.0±1.92ns +0.07%
Symbols (Execution) 3.1±0.01µs 3.0±0.01µs -3.23%
Symbols (Parser) 5.0±0.01µs 5.6±0.01µs +12.00%

@Razican
Copy link
Member

Razican commented Mar 21, 2023

Looking at the benchmarks, it seems that opting-out makes things slower than before

@HalidOdat
Copy link
Member Author

Looking at the benchmarks, it seems that opting-out makes things slower than before

I disabled optimizations in the benchmarks.

The benchmarks don't seem right, benchmarks like Create Realm have a +13.00% 😕 , it's not even related to this PR.

The opt-out only adds one condition check that is called once at the top level (parse_script function), its not something to cause that big of change in the benchmarks.

@HalidOdat HalidOdat force-pushed the optimization/constant-folding branch from 97633b6 to 3617c8d Compare March 21, 2023 13:05
@github-actions
Copy link

Benchmark for 84abb56

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 682.1±1.21ns 669.3±2.64ns -1.88%
Arithmetic operations (Execution) 562.6±1.03ns 711.5±0.95ns +26.47%
Arithmetic operations (Parser) 7.8±0.02µs 7.7±0.07µs -1.28%
Array access (Compiler) 1955.7±3.68ns 1963.8±4.43ns +0.41%
Array access (Execution) 8.8±0.02µs 8.6±0.06µs -2.27%
Array access (Parser) 16.0±0.03µs 15.9±0.02µs -0.62%
Array creation (Compiler) 2.8±0.00µs 2.8±0.01µs 0.00%
Array creation (Execution) 1283.2±1.74µs 1221.8±5.32µs -4.78%
Array creation (Parser) 19.3±0.04µs 19.3±0.02µs 0.00%
Array pop (Compiler) 5.4±0.01µs 5.0±0.01µs -7.41%
Array pop (Execution) 732.4±1.44µs 713.9±1.71µs -2.53%
Array pop (Parser) 175.2±0.25µs 175.3±0.20µs +0.06%
Boolean Object Access (Compiler) 1351.9±3.59ns 1346.5±7.44ns -0.40%
Boolean Object Access (Execution) 5.0±0.01µs 5.0±0.01µs 0.00%
Boolean Object Access (Parser) 20.3±0.03µs 20.2±0.02µs -0.49%
Clean js (Compiler) 5.7±0.02µs 5.7±0.01µs 0.00%
Clean js (Execution) 716.5±3.40µs 716.6±4.67µs +0.01%
Clean js (Parser) 41.0±0.07µs 40.4±0.06µs -1.46%
Create Realm 538.5±1.28µs 529.7±10.69µs -1.63%
Dynamic Object Property Access (Compiler) 2.3±0.01µs 2.3±0.01µs 0.00%
Dynamic Object Property Access (Execution) 5.6±0.02µs 5.5±0.01µs -1.79%
Dynamic Object Property Access (Parser) 14.1±0.07µs 14.1±0.02µs 0.00%
Fibonacci (Compiler) 3.5±0.01µs 3.6±0.01µs +2.86%
Fibonacci (Execution) 1254.4±4.21µs 1197.5±3.01µs -4.54%
Fibonacci (Parser) 23.1±0.04µs 23.0±0.08µs -0.43%
For loop (Compiler) 3.2±0.01µs 3.2±0.02µs 0.00%
For loop (Execution) 20.1±0.06µs 19.7±0.05µs -1.99%
For loop (Parser) 20.0±0.18µs 19.9±0.04µs -0.50%
Mini js (Compiler) 5.1±0.01µs 5.1±0.01µs 0.00%
Mini js (Execution) 659.4±2.84µs 664.3±4.30µs +0.74%
Mini js (Parser) 35.6±0.19µs 35.2±0.07µs -1.12%
Number Object Access (Compiler) 1288.2±3.95ns 1286.6±3.84ns -0.12%
Number Object Access (Execution) 3.9±0.01µs 3.8±0.01µs -2.56%
Number Object Access (Parser) 15.4±0.04µs 15.3±0.04µs -0.65%
Object Creation (Compiler) 2.1±0.01µs 2.1±0.00µs 0.00%
Object Creation (Execution) 5.3±0.02µs 5.2±0.01µs -1.89%
Object Creation (Parser) 12.6±0.04µs 12.4±0.03µs -1.59%
RegExp (Compiler) 2.4±0.01µs 2.3±0.01µs -4.17%
RegExp (Execution) 14.8±0.05µs 14.3±0.08µs -3.38%
RegExp (Parser) 13.8±0.02µs 13.9±0.02µs +0.72%
RegExp Creation (Compiler) 2.1±0.01µs 2.1±0.01µs 0.00%
RegExp Creation (Execution) 10.5±0.04µs 10.1±0.04µs -3.81%
RegExp Creation (Parser) 11.5±0.03µs 11.6±0.04µs +0.87%
RegExp Literal (Compiler) 2.4±0.01µs 2.3±0.01µs -4.17%
RegExp Literal (Execution) 14.8±0.06µs 14.2±0.06µs -4.05%
RegExp Literal (Parser) 15.4±0.02µs 15.4±0.05µs 0.00%
RegExp Literal Creation (Compiler) 2.1±0.01µs 2.1±0.00µs 0.00%
RegExp Literal Creation (Execution) 10.5±0.03µs 10.1±0.04µs -3.81%
RegExp Literal Creation (Parser) 13.2±0.03µs 13.2±0.04µs 0.00%
Static Object Property Access (Compiler) 2.2±0.01µs 2.1±0.00µs -4.55%
Static Object Property Access (Execution) 5.4±0.01µs 5.3±0.01µs -1.85%
Static Object Property Access (Parser) 13.6±0.02µs 13.3±0.03µs -2.21%
String Object Access (Compiler) 1737.4±3.07ns 1730.0±3.96ns -0.43%
String Object Access (Execution) 6.8±0.02µs 6.8±0.03µs 0.00%
String Object Access (Parser) 19.5±0.02µs 19.4±0.04µs -0.51%
String comparison (Compiler) 2.9±0.00µs 2.9±0.00µs 0.00%
String comparison (Execution) 4.9±0.02µs 4.6±0.04µs -6.12%
String comparison (Parser) 15.5±0.03µs 15.6±0.03µs +0.65%
String concatenation (Compiler) 2.3±0.00µs 2.3±0.01µs 0.00%
String concatenation (Execution) 4.5±0.01µs 4.3±0.03µs -4.44%
String concatenation (Parser) 10.5±0.02µs 10.6±0.02µs +0.95%
String copy (Compiler) 1962.5±3.39ns 1937.1±6.13ns -1.29%
String copy (Execution) 4.3±0.02µs 4.1±0.01µs -4.65%
String copy (Parser) 7.8±0.02µs 7.8±0.01µs 0.00%
Symbols (Compiler) 1418.3±4.38ns 1413.6±4.44ns -0.33%
Symbols (Execution) 4.4±0.02µs 4.1±0.01µs -6.82%
Symbols (Parser) 6.0±0.01µs 5.9±0.09µs -1.67%

@HalidOdat HalidOdat force-pushed the optimization/constant-folding branch from 3617c8d to bd251bd Compare March 25, 2023 18:26
@github-actions
Copy link

Benchmark for 3c883b4

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 784.5±61.57ns 807.3±61.74ns +2.91%
Arithmetic operations (Execution) 478.2±103.25ns 548.9±30.10ns +14.78%
Arithmetic operations (Parser) 9.2±0.82µs 9.0±0.72µs -2.17%
Array access (Compiler) 2.3±0.18µs 2.3±0.14µs 0.00%
Array access (Execution) 10.3±0.89µs 10.4±0.65µs +0.97%
Array access (Parser) 19.3±1.60µs 19.1±1.04µs -1.04%
Array creation (Compiler) 3.3±0.20µs 3.4±0.23µs +3.03%
Array creation (Execution) 1329.1±138.78µs 1311.4±112.85µs -1.33%
Array creation (Parser) 23.0±1.88µs 23.1±1.27µs +0.43%
Array pop (Compiler) 6.0±0.44µs 5.6±0.41µs -6.67%
Array pop (Execution) 795.9±57.06µs 779.0±47.78µs -2.12%
Array pop (Parser) 205.0±15.09µs 206.7±17.30µs +0.83%
Boolean Object Access (Compiler) 1609.3±181.68ns 1635.6±107.15ns +1.63%
Boolean Object Access (Execution) 5.5±0.33µs 5.6±0.47µs +1.82%
Boolean Object Access (Parser) 23.2±1.81µs 23.4±1.79µs +0.86%
Clean js (Compiler) 6.7±0.37µs 6.9±0.51µs +2.99%
Clean js (Execution) 792.2±43.77µs 783.9±49.56µs -1.05%
Clean js (Parser) 49.6±5.39µs 48.8±3.44µs -1.61%
Create Realm 590.2±35.53µs 599.9±38.93µs +1.64%
Dynamic Object Property Access (Compiler) 2.8±0.20µs 2.8±0.22µs 0.00%
Dynamic Object Property Access (Execution) 6.6±0.38µs 6.6±0.50µs 0.00%
Dynamic Object Property Access (Parser) 17.3±1.33µs 17.6±1.37µs +1.73%
Fibonacci (Compiler) 4.1±0.32µs 4.3±0.33µs +4.88%
Fibonacci (Execution) 1407.8±92.90µs 1550.3±107.89µs +10.12%
Fibonacci (Parser) 27.9±2.45µs 27.6±1.77µs -1.08%
For loop (Compiler) 3.9±0.84µs 3.9±0.30µs 0.00%
For loop (Execution) 21.5±1.74µs 23.4±3.73µs +8.84%
For loop (Parser) 24.0±1.96µs 23.9±2.23µs -0.42%
Mini js (Compiler) 6.2±0.41µs 6.4±0.54µs +3.23%
Mini js (Execution) 730.1±59.12µs 742.8±54.83µs +1.74%
Mini js (Parser) 42.9±3.21µs 42.0±3.13µs -2.10%
Number Object Access (Compiler) 1489.4±92.84ns 1542.0±126.83ns +3.53%
Number Object Access (Execution) 4.4±0.54µs 4.3±0.45µs -2.27%
Number Object Access (Parser) 17.9±1.51µs 18.7±1.99µs +4.47%
Object Creation (Compiler) 2.4±0.18µs 2.5±0.17µs +4.17%
Object Creation (Execution) 6.3±1.36µs 6.4±0.46µs +1.59%
Object Creation (Parser) 15.4±1.10µs 15.0±1.29µs -2.60%
RegExp (Compiler) 2.7±0.20µs 2.8±0.18µs +3.70%
RegExp (Execution) 17.4±1.40µs 17.3±1.28µs -0.57%
RegExp (Parser) 16.5±1.38µs 16.2±1.37µs -1.82%
RegExp Creation (Compiler) 2.4±0.15µs 2.5±0.21µs +4.17%
RegExp Creation (Execution) 11.6±0.78µs 11.6±0.82µs 0.00%
RegExp Creation (Parser) 14.0±0.90µs 14.0±1.10µs 0.00%
RegExp Literal (Compiler) 2.7±0.19µs 2.7±0.27µs 0.00%
RegExp Literal (Execution) 17.7±1.76µs 17.1±1.64µs -3.39%
RegExp Literal (Parser) 18.0±1.34µs 18.5±1.35µs +2.78%
RegExp Literal Creation (Compiler) 2.4±0.24µs 2.6±0.40µs +8.33%
RegExp Literal Creation (Execution) 11.8±0.78µs 11.9±1.08µs +0.85%
RegExp Literal Creation (Parser) 15.7±2.17µs 15.4±0.96µs -1.91%
Static Object Property Access (Compiler) 2.5±0.36µs 2.5±0.13µs 0.00%
Static Object Property Access (Execution) 6.4±0.45µs 6.5±0.44µs +1.56%
Static Object Property Access (Parser) 16.2±1.52µs 16.5±1.24µs +1.85%
String Object Access (Compiler) 2.0±0.21µs 2.1±0.13µs +5.00%
String Object Access (Execution) 7.7±0.60µs 7.6±0.56µs -1.30%
String Object Access (Parser) 23.0±2.08µs 22.3±1.61µs -3.04%
String comparison (Compiler) 3.4±0.26µs 3.5±0.34µs +2.94%
String comparison (Execution) 5.9±0.48µs 5.6±0.41µs -5.08%
String comparison (Parser) 18.1±1.45µs 18.5±1.14µs +2.21%
String concatenation (Compiler) 2.7±0.48µs 2.8±0.16µs +3.70%
String concatenation (Execution) 5.4±0.38µs 5.4±0.35µs 0.00%
String concatenation (Parser) 12.4±1.63µs 13.3±1.56µs +7.26%
String copy (Compiler) 2.3±0.17µs 2.4±0.28µs +4.35%
String copy (Execution) 5.1±0.41µs 5.1±0.34µs 0.00%
String copy (Parser) 9.6±1.45µs 9.5±0.67µs -1.04%
Symbols (Compiler) 1679.5±141.70ns 1703.4±108.89ns +1.42%
Symbols (Execution) 5.1±0.42µs 5.2±0.32µs +1.96%
Symbols (Parser) 7.2±0.41µs 7.3±0.66µs +1.39%

- Optimizer statistics
- Make optimization opt-out and disable them in benchmarks
@HalidOdat HalidOdat force-pushed the optimization/constant-folding branch from bd251bd to 7637200 Compare March 30, 2023 05:30
Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! :) great way to start optimizing

@Razican
Copy link
Member

Razican commented Mar 30, 2023

@jedel1043 are your concerns solved?

@github-actions
Copy link

Benchmark for 39e9b10

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 556.7±1.13ns 600.6±3.02ns +7.89%
Arithmetic operations (Execution) 373.2±1.09ns 450.4±3.71ns +20.69%
Arithmetic operations (Parser) 7.0±0.01µs 7.0±0.01µs 0.00%
Array access (Compiler) 1617.5±4.19ns 1678.8±5.53ns +3.79%
Array access (Execution) 7.1±0.01µs 7.2±0.01µs +1.41%
Array access (Parser) 14.3±0.02µs 14.6±0.01µs +2.10%
Array creation (Compiler) 2.3±0.04µs 2.4±0.01µs +4.35%
Array creation (Execution) 981.7±1.19µs 981.7±5.27µs 0.00%
Array creation (Parser) 17.3±0.03µs 17.5±0.02µs +1.16%
Array pop (Compiler) 4.4±0.01µs 4.5±0.01µs +2.27%
Array pop (Execution) 596.4±1.33µs 585.6±2.21µs -1.81%
Array pop (Parser) 148.5±0.13µs 153.1±0.13µs +3.10%
Boolean Object Access (Compiler) 1186.9±1.80ns 1204.4±3.48ns +1.47%
Boolean Object Access (Execution) 3.9±0.00µs 4.0±0.01µs +2.56%
Boolean Object Access (Parser) 18.1±0.02µs 18.2±0.03µs +0.55%
Clean js (Compiler) 4.9±0.01µs 4.9±0.01µs 0.00%
Clean js (Execution) 595.5±2.38µs 589.9±3.75µs -0.94%
Clean js (Parser) 36.4±0.05µs 37.0±0.04µs +1.65%
Create Realm 418.3±1.05µs 416.4±1.14µs -0.45%
Dynamic Object Property Access (Compiler) 1872.0±3.86ns 1908.8±3.69ns +1.97%
Dynamic Object Property Access (Execution) 4.5±0.01µs 4.6±0.01µs +2.22%
Dynamic Object Property Access (Parser) 12.9±0.03µs 12.9±0.02µs 0.00%
Fibonacci (Compiler) 2.9±0.01µs 2.9±0.01µs 0.00%
Fibonacci (Execution) 1004.2±1.25µs 1047.8±3.20µs +4.34%
Fibonacci (Parser) 20.5±0.04µs 20.9±0.03µs +1.95%
For loop (Compiler) 2.6±0.00µs 2.6±0.00µs 0.00%
For loop (Execution) 15.5±0.13µs 15.8±0.02µs +1.94%
For loop (Parser) 17.5±0.11µs 17.9±0.02µs +2.29%
Mini js (Compiler) 4.3±0.01µs 4.4±0.01µs +2.33%
Mini js (Execution) 545.2±2.73µs 543.3±2.11µs -0.35%
Mini js (Parser) 31.7±0.05µs 32.2±0.04µs +1.58%
Number Object Access (Compiler) 1114.5±1.57ns 1111.3±37.76ns -0.29%
Number Object Access (Execution) 3.0±0.01µs 3.1±0.01µs +3.33%
Number Object Access (Parser) 13.8±0.04µs 13.8±0.02µs 0.00%
Object Creation (Compiler) 1703.7±2.07ns 1729.3±2.38ns +1.50%
Object Creation (Execution) 4.2±0.01µs 4.3±0.01µs +2.38%
Object Creation (Parser) 11.3±0.02µs 11.3±0.02µs 0.00%
RegExp (Compiler) 1903.1±2.84ns 1916.0±3.67ns +0.68%
RegExp (Execution) 12.0±0.06µs 12.0±0.07µs 0.00%
RegExp (Parser) 12.3±0.02µs 12.4±0.02µs +0.81%
RegExp Creation (Compiler) 1685.2±2.47ns 1710.5±3.18ns +1.50%
RegExp Creation (Execution) 8.4±0.02µs 8.6±0.02µs +2.38%
RegExp Creation (Parser) 10.4±0.02µs 10.5±0.05µs +0.96%
RegExp Literal (Compiler) 1897.7±1.67ns 1921.8±3.90ns +1.27%
RegExp Literal (Execution) 12.1±0.06µs 12.0±0.05µs -0.83%
RegExp Literal (Parser) 13.8±0.03µs 13.7±0.03µs -0.72%
RegExp Literal Creation (Compiler) 1684.7±2.65ns 1709.9±2.19ns +1.50%
RegExp Literal Creation (Execution) 8.4±0.02µs 8.5±0.01µs +1.19%
RegExp Literal Creation (Parser) 11.8±0.02µs 11.7±0.02µs -0.85%
Static Object Property Access (Compiler) 1720.2±8.62ns 1743.4±2.38ns +1.35%
Static Object Property Access (Execution) 4.4±0.01µs 4.5±0.02µs +2.27%
Static Object Property Access (Parser) 12.2±0.02µs 12.3±0.02µs +0.82%
String Object Access (Compiler) 1487.6±2.76ns 1511.4±4.39ns +1.60%
String Object Access (Execution) 5.5±0.01µs 5.5±0.02µs 0.00%
String Object Access (Parser) 17.4±0.03µs 17.4±0.02µs 0.00%
String comparison (Compiler) 2.4±0.00µs 2.4±0.00µs 0.00%
String comparison (Execution) 3.8±0.01µs 3.9±0.01µs +2.63%
String comparison (Parser) 13.7±0.17µs 14.2±0.01µs +3.65%
String concatenation (Compiler) 1929.0±3.21ns 1947.4±2.71ns +0.95%
String concatenation (Execution) 3.5±0.02µs 3.6±0.01µs +2.86%
String concatenation (Parser) 9.5±0.04µs 9.7±0.02µs +2.11%
String copy (Compiler) 1600.1±2.85ns 1599.0±3.77ns -0.07%
String copy (Execution) 3.4±0.01µs 3.4±0.01µs 0.00%
String copy (Parser) 7.1±0.01µs 7.2±0.01µs +1.41%
Symbols (Compiler) 1172.4±2.82ns 1188.0±9.01ns +1.33%
Symbols (Execution) 3.4±0.02µs 3.5±0.01µs +2.94%
Symbols (Parser) 5.6±0.02µs 5.6±0.01µs 0.00%

Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jedel1043 are your concerns solved?

Yep, no more comments from my part. We can merge this :)

@jedel1043
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Mar 30, 2023
This PR implements an optimizer, It currently implements the [constant folding optimization][cfo]. this optimization is responsible for "folding"/evaluating constant expressions.

For example:

```js
let x = ((1 + 2 + -4) * 8) << 4
```
Generates the following instruction(s) (`cargo run -- -t`):
```
000000    0000    PushOne
000001    0001    PushInt8                   2
000003    0002    Add
000004    0003    PushInt8                   4
000006    0004    Neg
000007    0005    Add
000008    0006    PushInt8                   8
000010    0007    Mul
000011    0008    PushInt8                   4
000013    0009    ShiftLeft
000014    0010    DefInitLet                 0000: 'x'
```

With constant folding it generates the following instruction(s) (`cargo run -- -t -O`):
```
000000    0000    PushInt8                   -128
000002    0001    DefInitLet                 0000: 'x'
```

It changes the following:
- Implement ~~WIP~~ constant folding optimization, ~~only works with integers for now~~
- Add `--optimize, -O` flag to boa_cli
- Add `--optimizer-statistics` flag to boa_cli for optimizer statistics
- Add `--optimize, -O` flag to boa_tester

After I finish with this, will try to implement other optimizations :)

[cfo]: https://en.wikipedia.org/wiki/Constant_folding
@bors
Copy link

bors bot commented Mar 30, 2023

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title Implement constant folding optimization [Merged by Bors] - Implement constant folding optimization Mar 30, 2023
@bors bors bot closed this Mar 30, 2023
@bors bors bot deleted the optimization/constant-folding branch March 30, 2023 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance related changes and issues run-benchmark Label used to run banchmarks on PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants