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

Value refactor #498

Merged
merged 1 commit into from
Jun 23, 2020
Merged

Value refactor #498

merged 1 commit into from
Jun 23, 2020

Conversation

HalidOdat
Copy link
Member

@HalidOdat HalidOdat commented Jun 16, 2020

This Pull Request fixes/closes #465

It changes the following:

  • Moved Gc<...> => Value::Object(Gc<GcCell<Object>>)
  • Renamed ValueData => Value
  • Added reference counted RcString, RcSymbol, RcBigInt
  • Refactor Value::String(String) => Value::String(RcString)
  • Refactor Value::Symbol(Symbol) => Value::Symbol(RcSymbol)
  • Refactor Value::BigInt(BigInt) => Value::BigInt(RcBigInt)
  • Abstracted Gc<GcCell<Object>> => GcObject
  • Dropped Value size from 40 bytes => 24 bytes
  • Changed function signature this, from &mut Value => &Value
  • Removed Interpreter::value_to_rust_number()
  • Removed unnecessary Boxs in global environment
  • Extracted extensible for internal_slots
  • Made to_primitive, ordinary_to_primitive and Value::equals throw errors.
  • Removed strict parameter of SameValue (it is not dependent on strict mode)

@HalidOdat HalidOdat added performance Performance related changes and issues technical debt builtins PRs and Issues related to builtins/intrinsics labels Jun 16, 2020
@HalidOdat HalidOdat added this to the v0.9.0 milestone Jun 16, 2020
@codecov
Copy link

codecov bot commented Jun 16, 2020

Codecov Report

Merging #498 into master will increase coverage by 0.18%.
The diff coverage is 60.03%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #498      +/-   ##
==========================================
+ Coverage   67.88%   68.06%   +0.18%     
==========================================
  Files         165      169       +4     
  Lines        9932     9918      -14     
==========================================
+ Hits         6742     6751       +9     
+ Misses       3190     3167      -23     
Impacted Files Coverage Δ
boa/src/builtins/boolean/mod.rs 36.66% <0.00%> (ø)
boa/src/builtins/boolean/tests.rs 100.00% <ø> (ø)
boa/src/builtins/error/mod.rs 28.00% <0.00%> (ø)
boa/src/builtins/value/val_type.rs 20.83% <ø> (ø)
boa/src/environment/global_environment_record.rs 26.80% <ø> (+1.03%) ⬆️
boa/src/environment/lexical_environment.rs 74.75% <ø> (+0.22%) ⬆️
boa/src/builtins/console/mod.rs 27.17% <4.34%> (ø)
boa/src/builtins/object/internal_methods.rs 29.84% <8.00%> (-1.01%) ⬇️
boa/src/builtins/value/hash.rs 41.17% <30.00%> (-3.27%) ⬇️
boa/src/builtins/value/rcsymbol.rs 37.50% <37.50%> (ø)
... and 47 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 69f4886...ca0fa50. Read the comment docs.

@github-actions
Copy link

Benchmark for 20b71c0

Click to view benchmark
Test PR Benchmark Master Benchmark %
Array access (Execution) 14.8±0.60µs 27.8±0.94µs -46.76%
Array creation (Execution) 4.1±0.10ms 7.2±0.09ms -43.06%
Array pop (Execution) 1535.6±49.10µs 2.6±0.05ms -40.94%
Boolean Object Access (Execution) 6.8±0.39µs 9.6±0.25µs -29.17%
Create Realm 151.2±5.11µs 192.0±4.39µs -21.25%
Dynamic Object Property Access (Execution) 8.3±0.68µs 12.8±0.42µs -35.16%
Expression (Lexer) 2.2±0.11µs 2.2±0.06µs 0.00%
Expression (Parser) 5.3±0.14µs 5.3±0.21µs 0.00%
Fibonacci (Execution) 1146.6±35.57µs 2.2±0.05ms -47.88%
For loop (Execution) 26.2±1.19µs 61.6±1.30µs -57.47%
For loop (Lexer) 5.6±0.22µs 5.5±0.17µs +1.82%
For loop (Parser) 14.2±0.31µs 14.2±0.38µs 0.00%
Hello World (Lexer) 987.4±84.94ns 968.0±20.82ns +2.00%
Hello World (Parser) 2.3±0.06µs 2.3±0.06µs 0.00%
Long file (Parser) 6.4±0.13ms 6.4±0.10ms 0.00%
Number Object Access (Execution) 5.2±0.19µs 8.0±0.43µs -35.00%
Object Creation (Execution) 7.4±0.29µs 11.1±0.35µs -33.33%
RegExp (Execution) 79.1±5.55µs 81.8±3.31µs -3.30%
RegExp Literal (Execution) 81.0±2.73µs 86.1±2.46µs -5.92%
RegExp Literal Creation (Execution) 77.0±2.87µs 82.1±3.02µs -6.21%
Static Object Property Access (Execution) 7.6±0.24µs 11.6±0.40µs -34.48%
String Object Access (Execution) 11.0±0.61µs 16.8±0.45µs -34.52%
String comparison (Execution) 8.2±0.32µs 12.0±0.50µs -31.67%
String concatenation (Execution) 6.9±0.41µs 9.9±0.31µs -30.30%
String copy (Execution) 5.5±0.15µs 8.1±0.31µs -32.10%
Symbols (Execution) 4.8±0.21µs 9.1±0.21µs -47.25%

@HalidOdat
Copy link
Member Author

Woww. The benchmarks are awesome. I did not expect that big of an improvement from an initial refactor of Value. There is still a lot to do from #465.

@HalidOdat
Copy link
Member Author

Apparently Trace is not implemented for Rc, made a PR Manishearth/rust-gc#106

@github-actions
Copy link

Benchmark for 0813346

Click to view benchmark
Test PR Benchmark Master Benchmark %
Array access (Execution) 13.0±1.19µs 23.0±1.54µs -43.48%
Array creation (Execution) 3.2±0.28ms 5.4±0.28ms -40.74%
Array pop (Execution) 1347.6±105.35µs 1994.4±91.06µs -32.43%
Boolean Object Access (Execution) 5.3±0.44µs 8.3±0.49µs -36.14%
Create Realm 129.6±10.29µs 161.8±12.64µs -19.90%
Dynamic Object Property Access (Execution) 7.1±0.44µs 11.3±0.61µs -37.17%
Expression (Lexer) 1844.1±173.40ns 1809.0±345.97ns +1.94%
Expression (Parser) 3.9±0.28µs 4.0±0.52µs -2.50%
Fibonacci (Execution) 1016.3±56.52µs 1950.5±129.41µs -47.90%
For loop (Execution) 21.4±1.10µs 57.5±4.03µs -62.78%
For loop (Lexer) 4.4±0.37µs 4.3±0.25µs +2.33%
For loop (Parser) 11.2±0.73µs 11.4±1.21µs -1.75%
Hello World (Lexer) 772.5±64.57ns 786.1±54.05ns -1.73%
Hello World (Parser) 1771.8±117.64ns 1868.5±166.86ns -5.18%
Long file (Parser) 5.2±0.19ms 5.3±0.30ms -1.89%
Number Object Access (Execution) 4.1±0.23µs 7.0±0.69µs -41.43%
Object Creation (Execution) 6.7±0.46µs 9.6±0.58µs -30.21%
RegExp (Execution) 66.9±6.69µs 70.3±4.71µs -4.84%
RegExp Literal (Execution) 70.8±3.42µs 75.8±5.71µs -6.60%
RegExp Literal Creation (Execution) 66.7±3.55µs 70.3±4.85µs -5.12%
Static Object Property Access (Execution) 6.7±0.82µs 9.8±0.81µs -31.63%
String Object Access (Execution) 8.7±0.60µs 14.7±1.27µs -40.82%
String comparison (Execution) 6.9±0.65µs 9.8±0.89µs -29.59%
String concatenation (Execution) 5.7±0.44µs 8.8±1.01µs -35.23%
String copy (Execution) 4.7±0.33µs 7.3±0.45µs -35.62%
Symbols (Execution) 4.2±0.33µs 7.7±0.63µs -45.45%

@github-actions
Copy link

Benchmark for b160799

Click to view benchmark
Test PR Benchmark Master Benchmark %
Array access (Execution) 15.1±0.63µs 25.6±1.52µs -41.02%
Array creation (Execution) 3.9±0.20ms 6.7±0.20ms -41.79%
Array pop (Execution) 1503.8±112.95µs 2.4±0.11ms -37.34%
Boolean Object Access (Execution) 6.0±0.28µs 9.3±0.47µs -35.48%
Create Realm 149.5±7.75µs 187.0±7.48µs -20.05%
Dynamic Object Property Access (Execution) 8.2±0.56µs 11.7±0.59µs -29.91%
Expression (Lexer) 2.0±0.11µs 2.0±0.11µs 0.00%
Expression (Parser) 4.9±0.22µs 4.7±0.26µs +4.26%
Fibonacci (Execution) 1064.4±44.99µs 1985.3±86.59µs -46.39%
For loop (Execution) 24.6±1.45µs 58.1±3.27µs -57.66%
For loop (Lexer) 5.3±0.25µs 5.2±0.30µs +1.92%
For loop (Parser) 13.8±0.79µs 13.4±0.67µs +2.99%
Hello World (Lexer) 926.2±40.69ns 883.1±42.38ns +4.88%
Hello World (Parser) 2.2±0.12µs 2.2±0.15µs 0.00%
Long file (Parser) 6.3±0.23ms 6.2±0.22ms +1.61%
Number Object Access (Execution) 4.9±0.41µs 7.2±0.37µs -31.94%
Object Creation (Execution) 7.0±0.38µs 10.4±0.83µs -32.69%
RegExp (Execution) 72.6±4.52µs 75.8±6.82µs -4.22%
RegExp Literal (Execution) 75.7±3.58µs 81.5±6.96µs -7.12%
RegExp Literal Creation (Execution) 74.4±4.87µs 76.8±5.07µs -3.12%
Static Object Property Access (Execution) 7.4±0.56µs 10.8±0.82µs -31.48%
String Object Access (Execution) 10.3±0.64µs 15.6±0.77µs -33.97%
String comparison (Execution) 7.6±0.36µs 10.7±0.50µs -28.97%
String concatenation (Execution) 6.4±0.28µs 9.0±0.43µs -28.89%
String copy (Execution) 5.5±0.39µs 7.4±0.38µs -25.68%
Symbols (Execution) 4.7±0.27µs 8.2±0.49µs -42.68%

@github-actions
Copy link

Benchmark for 9f00b7c

Click to view benchmark
Test PR Benchmark Master Benchmark %
Array access (Execution) 15.2±0.84µs 27.0±1.09µs -43.70%
Array creation (Execution) 3.8±0.15ms 6.5±0.22ms -41.54%
Array pop (Execution) 1429.3±59.25µs 2.4±0.10ms -40.45%
Boolean Object Access (Execution) 6.0±0.39µs 9.9±0.48µs -39.39%
Create Realm 150.2±8.79µs 196.2±9.13µs -23.45%
Dynamic Object Property Access (Execution) 8.2±0.48µs 12.6±0.57µs -34.92%
Expression (Lexer) 2.1±0.11µs 2.1±0.10µs 0.00%
Expression (Parser) 5.0±0.25µs 4.9±0.22µs +2.04%
Fibonacci (Execution) 1196.7±59.64µs 2.2±0.12ms -45.60%
For loop (Execution) 25.2±1.82µs 65.0±2.75µs -61.23%
For loop (Lexer) 5.2±0.25µs 5.4±0.43µs -3.70%
For loop (Parser) 14.2±0.97µs 13.5±1.00µs +5.19%
Hello World (Lexer) 955.5±62.81ns 949.1±52.33ns +0.67%
Hello World (Parser) 2.3±0.15µs 2.2±0.09µs +4.55%
Long file (Parser) 6.3±0.21ms 6.1±0.29ms +3.28%
Number Object Access (Execution) 4.8±0.18µs 8.3±0.50µs -42.17%
Object Creation (Execution) 7.4±0.28µs 11.3±0.61µs -34.51%
RegExp (Execution) 79.2±5.00µs 85.1±4.77µs -6.93%
RegExp Literal (Execution) 84.3±6.24µs 90.9±8.57µs -7.26%
RegExp Literal Creation (Execution) 79.0±3.64µs 83.9±5.08µs -5.84%
Static Object Property Access (Execution) 7.4±0.37µs 11.6±0.68µs -36.21%
String Object Access (Execution) 10.1±0.59µs 16.9±0.91µs -40.24%
String comparison (Execution) 7.7±0.59µs 11.8±0.58µs -34.75%
String concatenation (Execution) 6.7±0.32µs 9.8±0.53µs -31.63%
String copy (Execution) 5.5±0.29µs 8.3±1.65µs -33.73%
Symbols (Execution) 4.8±0.22µs 8.8±0.41µs -45.45%

@HalidOdat
Copy link
Member Author

HalidOdat commented Jun 17, 2020

Size of Value (there is only Value now, no ValueData) has dropped from 40 bytes to 24 bytes

@github-actions
Copy link

Benchmark for de07dc4

Click to view benchmark
Test PR Benchmark Master Benchmark %
Array access (Execution) 15.7±0.76µs 27.6±2.39µs -43.12%
Array creation (Execution) 3.9±0.19ms 6.8±0.27ms -42.65%
Array pop (Execution) 1482.0±72.92µs 2.5±0.14ms -40.72%
Boolean Object Access (Execution) 6.3±0.33µs 10.0±0.62µs -37.00%
Create Realm 171.9±13.01µs 186.9±13.08µs -8.03%
Dynamic Object Property Access (Execution) 8.7±0.69µs 13.0±0.80µs -33.08%
Expression (Lexer) 2.2±0.15µs 2.2±0.14µs 0.00%
Expression (Parser) 5.1±0.27µs 5.3±0.33µs -3.77%
Fibonacci (Execution) 1189.7±73.45µs 2.3±0.12ms -48.27%
For loop (Execution) 26.0±1.80µs 68.7±4.90µs -62.15%
For loop (Lexer) 5.5±0.44µs 5.5±0.37µs 0.00%
For loop (Parser) 14.4±0.82µs 14.3±1.12µs +0.70%
Hello World (Lexer) 988.1±58.98ns 990.1±55.88ns -0.20%
Hello World (Parser) 2.3±0.12µs 2.3±0.12µs 0.00%
Long file (Parser) 6.5±0.31ms 6.6±0.21ms -1.52%
Number Object Access (Execution) 4.9±0.29µs 8.3±0.49µs -40.96%
Object Creation (Execution) 7.6±0.50µs 11.5±0.61µs -33.91%
RegExp (Execution) 79.9±5.28µs 85.9±6.00µs -6.98%
RegExp Literal (Execution) 86.2±7.05µs 93.3±11.02µs -7.61%
RegExp Literal Creation (Execution) 81.9±6.29µs 85.4±5.46µs -4.10%
Static Object Property Access (Execution) 7.9±0.50µs 12.0±0.66µs -34.17%
String Object Access (Execution) 10.4±1.01µs 17.0±1.00µs -38.82%
String comparison (Execution) 7.9±0.53µs 11.9±0.75µs -33.61%
String concatenation (Execution) 6.7±0.40µs 10.2±0.51µs -34.31%
String copy (Execution) 5.6±0.67µs 8.3±0.52µs -32.53%
Symbols (Execution) 4.9±0.38µs 9.3±0.46µs -47.31%

@github-actions
Copy link

Benchmark for d5b34c3

Click to view benchmark
Test PR Benchmark Master Benchmark %
Array access (Execution) 16.6±0.69µs 29.5±1.44µs -43.73%
Array creation (Execution) 4.2±0.11ms 7.3±0.18ms -42.47%
Array pop (Execution) 1611.1±84.44µs 2.7±0.13ms -40.33%
Boolean Object Access (Execution) 6.8±0.40µs 10.6±0.44µs -35.85%
Create Realm 180.4±7.90µs 201.1±6.45µs -10.29%
Dynamic Object Property Access (Execution) 9.2±0.34µs 14.2±0.66µs -35.21%
Expression (Lexer) 2.3±0.10µs 2.3±0.16µs 0.00%
Expression (Parser) 5.7±0.25µs 5.3±0.19µs +7.55%
Fibonacci (Execution) 1288.7±62.19µs 2.6±0.15ms -50.43%
For loop (Execution) 27.3±0.78µs 73.1±3.45µs -62.65%
For loop (Lexer) 5.8±0.24µs 5.8±0.21µs 0.00%
For loop (Parser) 15.3±0.57µs 15.0±0.43µs +2.00%
Hello World (Lexer) 1027.8±40.91ns 1059.9±75.49ns -3.03%
Hello World (Parser) 2.5±0.15µs 2.5±0.14µs 0.00%
Long file (Parser) 6.9±0.18ms 6.8±0.15ms +1.47%
Number Object Access (Execution) 5.3±0.22µs 8.6±0.26µs -38.37%
Object Creation (Execution) 8.0±0.27µs 12.5±0.47µs -36.00%
RegExp (Execution) 86.5±2.66µs 90.6±4.96µs -4.53%
RegExp Literal (Execution) 91.5±3.13µs 97.4±5.78µs -6.06%
RegExp Literal Creation (Execution) 85.9±3.20µs 95.0±8.31µs -9.58%
Static Object Property Access (Execution) 8.3±0.28µs 13.3±0.80µs -37.59%
String Object Access (Execution) 11.2±0.45µs 18.2±0.70µs -38.46%
String comparison (Execution) 8.7±0.26µs 12.9±0.60µs -32.56%
String concatenation (Execution) 7.3±0.15µs 11.1±0.88µs -34.23%
String copy (Execution) 6.1±0.28µs 9.3±3.91µs -34.41%
Symbols (Execution) 5.2±0.16µs 10.0±0.56µs -48.00%

@github-actions
Copy link

Benchmark for 5dff5c7

Click to view benchmark
Test PR Benchmark Master Benchmark %
Array access (Execution) 14.9±1.00µs 25.2±1.10µs -40.87%
Array creation (Execution) 3.9±0.13ms 6.7±0.14ms -41.79%
Array pop (Execution) 1466.3±22.08µs 2.4±0.06ms -38.90%
Boolean Object Access (Execution) 6.0±0.13µs 9.1±0.33µs -34.07%
Create Realm 159.8±8.63µs 197.4±7.42µs -19.05%
Dynamic Object Property Access (Execution) 7.9±0.15µs 12.2±0.28µs -35.25%
Expression (Lexer) 2.0±0.05µs 2.0±0.08µs 0.00%
Expression (Parser) 5.0±0.13µs 4.9±0.11µs +2.04%
Fibonacci (Execution) 1095.7±44.42µs 2.1±0.04ms -47.82%
For loop (Execution) 24.1±0.52µs 59.0±1.46µs -59.15%
For loop (Lexer) 5.3±0.13µs 5.2±0.16µs +1.92%
For loop (Parser) 13.7±0.38µs 13.2±1.09µs +3.79%
Hello World (Lexer) 914.8±26.32ns 907.6±18.21ns +0.79%
Hello World (Parser) 2.2±0.06µs 2.1±0.05µs +4.76%
Long file (Parser) 6.1±0.10ms 5.9±0.10ms +3.39%
Number Object Access (Execution) 4.7±0.17µs 7.3±0.15µs -35.62%
Object Creation (Execution) 7.0±0.26µs 10.4±0.30µs -32.69%
RegExp (Execution) 73.3±1.88µs 75.9±2.10µs -3.43%
RegExp Literal (Execution) 77.3±2.06µs 79.3±2.14µs -2.52%
RegExp Literal Creation (Execution) 73.4±2.29µs 75.9±3.10µs -3.29%
Static Object Property Access (Execution) 7.3±0.48µs 10.7±0.29µs -31.78%
String Object Access (Execution) 9.8±0.20µs 15.8±0.50µs -37.97%
String comparison (Execution) 7.5±0.20µs 11.0±0.47µs -31.82%
String concatenation (Execution) 6.4±0.18µs 9.1±0.20µs -29.67%
String copy (Execution) 5.2±0.15µs 7.6±0.17µs -31.58%
Symbols (Execution) 4.6±0.10µs 8.5±0.60µs -45.88%

@github-actions
Copy link

Benchmark for f7daf82

Click to view benchmark
Test PR Benchmark Master Benchmark %
Array access (Execution) 14.7±0.85µs 29.0±1.97µs -49.31%
Array creation (Execution) 3.9±0.14ms 6.9±0.23ms -43.48%
Array pop (Execution) 1470.3±152.73µs 2.6±0.13ms -43.45%
Boolean Object Access (Execution) 5.8±0.36µs 10.8±0.66µs -46.30%
Create Realm 138.3±15.12µs 208.5±9.12µs -33.67%
Dynamic Object Property Access (Execution) 8.0±0.61µs 13.5±0.78µs -40.74%
Expression (Lexer) 2.2±0.09µs 2.3±0.20µs -4.35%
Expression (Parser) 5.2±0.26µs 5.9±0.35µs -11.86%
Fibonacci (Execution) 1130.1±63.71µs 2.4±0.20ms -52.91%
For loop (Execution) 24.6±1.21µs 68.6±3.76µs -64.14%
For loop (Lexer) 5.5±0.25µs 6.4±0.35µs -14.06%
For loop (Parser) 14.8±1.07µs 20.4±1.83µs -27.45%
Hello World (Lexer) 1035.0±69.50ns 1103.6±142.06ns -6.22%
Hello World (Parser) 2.4±0.15µs 2.8±0.20µs -14.29%
Long file (Parser) 6.7±0.43ms 6.7±0.20ms 0.00%
Number Object Access (Execution) 4.6±0.28µs 8.4±0.58µs -45.24%
Object Creation (Execution) 6.8±0.39µs 11.9±0.71µs -42.86%
RegExp (Execution) 85.0±7.06µs 87.6±5.98µs -2.97%
RegExp Literal (Execution) 87.2±5.31µs 92.7±5.90µs -5.93%
RegExp Literal Creation (Execution) 83.5±5.51µs 86.1±3.82µs -3.02%
Static Object Property Access (Execution) 7.0±0.42µs 12.5±0.71µs -44.00%
String Object Access (Execution) 9.7±0.56µs 18.3±1.41µs -46.99%
String comparison (Execution) 7.4±0.40µs 12.1±0.61µs -38.84%
String concatenation (Execution) 6.5±0.48µs 10.2±0.57µs -36.27%
String copy (Execution) 5.1±0.31µs 8.5±0.54µs -40.00%
Symbols (Execution) 4.5±0.27µs 9.2±0.44µs -51.09%

@github-actions
Copy link

Benchmark for aab0800

Click to view benchmark
Test PR Benchmark Master Benchmark %
Array access (Execution) 14.1±0.58µs 26.5±0.74µs -46.79%
Array creation (Execution) 3.9±0.13ms 6.9±0.13ms -43.48%
Array pop (Execution) 1454.8±29.79µs 2.5±0.21ms -41.81%
Boolean Object Access (Execution) 5.4±0.15µs 9.2±0.25µs -41.30%
Create Realm 132.8±3.79µs 201.7±11.04µs -34.16%
Dynamic Object Property Access (Execution) 7.4±1.55µs 12.2±0.39µs -39.34%
Expression (Lexer) 2.1±0.04µs 2.1±0.06µs 0.00%
Expression (Parser) 5.2±0.19µs 5.1±0.10µs +1.96%
Fibonacci (Execution) 977.8±16.99µs 2.1±0.14ms -53.44%
For loop (Execution) 23.9±0.97µs 60.2±2.24µs -60.30%
For loop (Lexer) 5.3±0.13µs 5.3±0.21µs 0.00%
For loop (Parser) 13.9±0.36µs 13.6±0.29µs +2.21%
Hello World (Lexer) 946.9±41.30ns 925.6±25.66ns +2.30%
Hello World (Parser) 2.2±0.05µs 2.2±0.10µs 0.00%
Long file (Parser) 6.2±0.10ms 6.1±0.09ms +1.64%
Number Object Access (Execution) 4.3±0.11µs 7.4±0.10µs -41.89%
Object Creation (Execution) 6.2±0.29µs 10.8±0.22µs -42.59%
RegExp (Execution) 73.0±3.49µs 78.2±2.95µs -6.65%
RegExp Literal (Execution) 76.3±2.37µs 83.3±2.85µs -8.40%
RegExp Literal Creation (Execution) 72.7±2.22µs 77.2±1.94µs -5.83%
Static Object Property Access (Execution) 6.3±0.15µs 11.1±0.32µs -43.24%
String Object Access (Execution) 9.0±0.67µs 16.1±0.52µs -44.10%
String comparison (Execution) 7.0±0.45µs 11.3±0.29µs -38.05%
String concatenation (Execution) 5.8±0.18µs 9.8±1.06µs -40.82%
String copy (Execution) 4.6±0.09µs 7.8±0.15µs -41.03%
Symbols (Execution) 4.1±0.11µs 8.5±0.18µs -51.76%

@HalidOdat
Copy link
Member Author

This is ready for review :) @Razican @jasonwilliams

@github-actions
Copy link

Benchmark for 62c19c0

Click to view benchmark
Test PR Benchmark Master Benchmark %
Array access (Execution) 12.7±0.55µs 23.7±1.10µs -46.41%
Array creation (Execution) 3.6±0.14ms 6.2±0.21ms -41.94%
Array pop (Execution) 1319.7±47.67µs 2.2±0.09ms -40.01%
Boolean Object Access (Execution) 5.0±0.21µs 8.4±0.41µs -40.48%
Create Realm 125.1±4.67µs 187.9±13.56µs -33.42%
Dynamic Object Property Access (Execution) 6.7±0.24µs 11.1±0.46µs -39.64%
Expression (Lexer) 1915.7±90.01ns 1863.9±103.16ns +2.78%
Expression (Parser) 4.6±0.21µs 4.6±0.23µs 0.00%
Fibonacci (Execution) 905.4±32.05µs 1957.1±74.61µs -53.74%
For loop (Execution) 21.1±0.89µs 53.9±2.12µs -60.85%
For loop (Lexer) 4.9±0.22µs 4.9±0.21µs 0.00%
For loop (Parser) 12.8±0.55µs 12.5±0.52µs +2.40%
Hello World (Lexer) 832.6±38.33ns 909.1±77.69ns -8.41%
Hello World (Parser) 2.0±0.11µs 2.1±0.14µs -4.76%
Long file (Parser) 5.6±0.16ms 5.7±0.15ms -1.75%
Number Object Access (Execution) 3.8±0.16µs 6.7±0.30µs -43.28%
Object Creation (Execution) 5.6±0.24µs 9.7±0.42µs -42.27%
RegExp (Execution) 64.8±3.49µs 71.1±3.76µs -8.86%
RegExp Literal (Execution) 67.8±3.32µs 75.1±3.03µs -9.72%
RegExp Literal Creation (Execution) 66.6±3.07µs 71.1±3.66µs -6.33%
Static Object Property Access (Execution) 5.7±0.28µs 10.1±0.44µs -43.56%
String Object Access (Execution) 8.3±0.39µs 14.7±0.64µs -43.54%
String comparison (Execution) 6.2±0.31µs 10.0±0.56µs -38.00%
String concatenation (Execution) 5.1±0.25µs 8.4±0.42µs -39.29%
String copy (Execution) 4.2±0.21µs 7.0±0.36µs -40.00%
Symbols (Execution) 3.9±0.17µs 7.8±0.32µs -50.00%

@github-actions
Copy link

Benchmark for aebb26e

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 512.1±34.25ns 2.7±0.17µs -81.03%
Array access (Execution) 13.1±0.77µs 25.2±1.94µs -48.02%
Array creation (Execution) 3.5±0.21ms 6.1±0.21ms -42.62%
Array pop (Execution) 1290.5±77.20µs 2.2±0.12ms -41.34%
Boolean Object Access (Execution) 5.1±0.39µs 8.9±0.46µs -42.70%
Create Realm 128.2±6.98µs 185.6±10.49µs -30.93%
Dynamic Object Property Access (Execution) 6.9±0.53µs 12.0±0.62µs -42.50%
Expression (Lexer) 1933.6±111.02ns 1912.6±110.55ns +1.10%
Expression (Parser) 4.6±0.32µs 4.5±0.32µs +2.22%
Fibonacci (Execution) 983.7±52.17µs 2.2±0.14ms -55.29%
For loop (Execution) 21.8±1.26µs 58.4±3.90µs -62.67%
For loop (Lexer) 5.1±0.48µs 4.9±0.34µs +4.08%
For loop (Parser) 12.6±0.75µs 12.9±1.03µs -2.33%
Hello World (Lexer) 874.2±64.18ns 853.9±43.43ns +2.38%
Hello World (Parser) 2.0±0.11µs 2.0±0.11µs 0.00%
Long file (Parser) 5.9±0.26ms 5.8±0.29ms +1.72%
Number Object Access (Execution) 3.9±0.23µs 7.3±0.43µs -46.58%
Object Creation (Execution) 6.2±0.37µs 10.4±0.60µs -40.38%
RegExp (Execution) 72.7±4.18µs 76.7±4.40µs -5.22%
RegExp Literal (Execution) 76.1±4.25µs 79.9±5.00µs -4.76%
RegExp Literal Creation (Execution) 72.8±4.68µs 75.8±4.58µs -3.96%
Static Object Property Access (Execution) 6.4±0.37µs 10.8±0.57µs -40.74%
String Object Access (Execution) 8.6±0.48µs 15.9±0.92µs -45.91%
String comparison (Execution) 6.5±0.36µs 11.0±0.94µs -40.91%
String concatenation (Execution) 5.7±0.33µs 9.5±0.61µs -40.00%
String copy (Execution) 4.4±0.25µs 7.6±0.53µs -42.11%
Symbols (Execution) 4.2±0.41µs 8.4±0.54µs -50.00%

@HalidOdat
Copy link
Member Author

HalidOdat commented Jun 22, 2020

I did a profile of master and refactor/value branches, here is the code that was executed: https://gist.github.com/HalidOdat/a11478d0d67a7150a6faf69c2126d717

The profile for master is here: https://gist.github.com/HalidOdat/795d1af25d706a4fad5bd381ac2dfb8c

master

And for refactor/value here: https://gist.github.com/HalidOdat/b5c7372d5d43912110fb6c46d84c3ea6
refactor_value

There is a 12ms difference between them.

BTW: The gap seems to disappear if I run it a lot with very little time in between, which makes me think that the the file is being cached, that's why sometimes it appears, and other times not.

@@ -28,7 +28,7 @@ use gc::{unsafe_empty_trace, Finalize, Trace};
use std::fmt::{self, Debug};

/// _fn(this, arguments, ctx) -> ResultValue_ - The signature of a built-in function
pub type NativeFunctionData = fn(&mut Value, &[Value], &mut Interpreter) -> ResultValue;
pub type NativeFunctionData = fn(&Value, &[Value], &mut Interpreter) -> ResultValue;
Copy link
Member

Choose a reason for hiding this comment

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

Whats the reason behind the change here?

Copy link
Member Author

@HalidOdat HalidOdat Jun 22, 2020

Choose a reason for hiding this comment

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

Whats the reason behind the change here?

It's because the Value does not need to be mutable itself, except Object and Object is covered in a GcCell<...> it has interior mutability, so we can borrow_mut the Object with a immutable reference to Value.

This eliminated some places where we were awkwardly cloning the value and passing it to a function because the builtin function required it (&mut value.clone()), instead of just passing the value direclty.

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.

Wow, benchmarks are amazing!! 80% reduction in arithmetic operations is crazy!

Check my comments, they are mostly a bit of cleanup, part of it not even related to the PR. I think this code is very good!

boa/src/builtins/array/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/object/gcobject.rs Outdated Show resolved Hide resolved
boa/src/builtins/object/gcobject.rs Outdated Show resolved Hide resolved
boa/src/builtins/regexp/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/regexp/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/string/mod.rs Show resolved Hide resolved
boa/src/builtins/string/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/string/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/string/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/string/mod.rs Outdated Show resolved Hide resolved
@github-actions
Copy link

Benchmark for 6de3aec

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 470.5±21.65ns 2.5±0.15µs -81.18%
Array access (Execution) 12.4±0.82µs 24.1±1.38µs -48.55%
Array creation (Execution) 3.3±0.13ms 5.8±0.22ms -43.10%
Array pop (Execution) 1226.4±60.17µs 2.1±0.10ms -41.60%
Boolean Object Access (Execution) 4.7±0.23µs 8.5±0.97µs -44.71%
Create Realm 120.2±7.13µs 174.5±8.65µs -31.12%
Dynamic Object Property Access (Execution) 6.6±0.44µs 11.3±0.67µs -41.59%
Expression (Lexer) 1785.1±94.26ns 1777.1±117.61ns +0.45%
Expression (Parser) 4.3±0.20µs 4.4±0.51µs -2.27%
Fibonacci (Execution) 946.8±39.34µs 2.0±0.09ms -52.66%
For loop (Execution) 20.6±1.02µs 56.1±3.23µs -63.28%
For loop (Lexer) 4.7±0.32µs 4.6±0.22µs +2.17%
For loop (Parser) 12.2±0.78µs 12.1±0.86µs +0.83%
Hello World (Lexer) 837.4±48.16ns 827.7±47.43ns +1.17%
Hello World (Parser) 1906.4±90.75ns 1895.4±96.15ns +0.58%
Long file (Parser) 5.5±0.17ms 5.5±0.22ms 0.00%
Number Object Access (Execution) 3.8±0.25µs 7.0±0.54µs -45.71%
Object Creation (Execution) 5.8±0.35µs 9.9±0.52µs -41.41%
RegExp (Execution) 68.1±7.00µs 73.8±5.17µs -7.72%
RegExp Literal (Execution) 73.5±3.76µs 79.0±4.14µs -6.96%
RegExp Literal Creation (Execution) 69.8±4.11µs 74.0±3.57µs -5.68%
Static Object Property Access (Execution) 5.8±0.30µs 10.0±0.50µs -42.00%
String Object Access (Execution) 7.9±0.51µs 14.5±0.71µs -45.52%
String comparison (Execution) 6.3±0.40µs 10.2±0.60µs -38.24%
String concatenation (Execution) 5.2±0.42µs 8.6±0.45µs -39.53%
String copy (Execution) 4.2±0.28µs 7.1±0.40µs -40.85%
Symbols (Execution) 3.7±0.16µs 7.9±0.38µs -53.16%

 - Refactor `String` => `Rc<str>`
 - Refactor `Symbol` => `Rc<Symbol>`
 - Refactor `BigInt` => `RcBigInt`
 - Changed function signature, from `&mut Value` to `&Value`
 - Removed `Interpreter::value_to_rust_number()
 - Abstracted `Gc<GcCell<Object>>` to `GcObject`
 - Removed unnecessary `Box`s in global environment
 - Extracted `extensible` from internal slots
 - Made `to_primitive` throw errors
 - Removed `strict` parameter in `SameValue` function.
 - The `SameValue` function is not dependent on strict mode.
@github-actions
Copy link

Benchmark for f951c8f

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 442.5±26.23ns 2.6±0.12µs -82.98%
Array access (Execution) 13.4±0.73µs 23.9±1.15µs -43.93%
Array creation (Execution) 3.7±0.11ms 6.1±0.53ms -39.34%
Array pop (Execution) 1391.4±55.07µs 2.0±0.18ms -30.43%
Boolean Object Access (Execution) 4.9±0.23µs 8.7±0.48µs -43.68%
Create Realm 130.7±5.70µs 186.3±12.69µs -29.84%
Dynamic Object Property Access (Execution) 6.8±0.26µs 11.1±0.58µs -38.74%
Expression (Lexer) 1927.1±94.45ns 1890.1±72.55ns +1.96%
Expression (Parser) 4.7±0.17µs 4.7±0.23µs 0.00%
Fibonacci (Execution) 957.2±29.46µs 2.0±0.11ms -52.14%
For loop (Execution) 22.5±0.73µs 54.2±2.33µs -58.49%
For loop (Lexer) 5.0±0.39µs 4.8±0.28µs +4.17%
For loop (Parser) 12.9±0.66µs 12.1±0.60µs +6.61%
Hello World (Lexer) 863.0±41.22ns 850.5±34.50ns +1.47%
Hello World (Parser) 2.1±0.09µs 2.0±0.10µs +5.00%
Long file (Parser) 5.6±0.18ms 5.7±0.17ms -1.75%
Number Object Access (Execution) 3.9±0.20µs 6.9±0.43µs -43.48%
Object Creation (Execution) 6.0±0.16µs 9.7±0.43µs -38.14%
RegExp (Execution) 69.8±1.90µs 70.5±4.16µs -0.99%
RegExp Literal (Execution) 73.8±2.73µs 74.3±3.48µs -0.67%
RegExp Literal Creation (Execution) 70.3±13.50µs 71.3±7.86µs -1.40%
Static Object Property Access (Execution) 6.1±0.15µs 10.1±0.53µs -39.60%
String Object Access (Execution) 7.0±0.52µs 14.8±0.68µs -52.70%
String comparison (Execution) 6.6±0.19µs 10.2±0.51µs -35.29%
String concatenation (Execution) 5.6±0.22µs 8.4±0.52µs -33.33%
String copy (Execution) 4.4±0.12µs 7.0±0.34µs -37.14%
Symbols (Execution) 4.0±0.15µs 7.8±0.29µs -48.72%

@HalidOdat
Copy link
Member Author

Lets merge this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builtins PRs and Issues related to builtins/intrinsics performance Performance related changes and issues technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactoring Value (decouple Gc from Value)
3 participants