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

Cache well known symbols #706

Merged
merged 3 commits into from
Sep 22, 2020
Merged

Conversation

HalidOdat
Copy link
Member

@HalidOdat HalidOdat commented Sep 18, 2020

#704 (comment)

It changes the following:

  • Add Context::well_known_symbols() method.
  • Add WellKnownSymbols struct
  • Add getters for the symbols to WellKnownSymbols struct

With this PR we can now do:

let mut context = Context::new();

let iterator = context.well_known_symbols().iterator_symbol();

instead of:

let mut context = Context::new();

let iterator = context.global_object().get_field("Symbol").get_field("iterator").as_symbol().unwrap();

Also there is a problem with this ^, what if we override Symbol object like:

globalThis.Symbol = 10;

Now the above code will panic, we should have a way to access the well known symbols without being tied to the global bindings.

What do you think? @joshwd36

@HalidOdat HalidOdat added enhancement New feature or request builtins PRs and Issues related to builtins/intrinsics API labels Sep 18, 2020
@HalidOdat HalidOdat added this to the v0.10.0 milestone Sep 18, 2020
@codecov
Copy link

codecov bot commented Sep 18, 2020

Codecov Report

Merging #706 into master will increase coverage by 0.03%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #706      +/-   ##
==========================================
+ Coverage   71.69%   71.72%   +0.03%     
==========================================
  Files         199      199              
  Lines       13865    13937      +72     
==========================================
+ Hits         9941     9997      +56     
- Misses       3924     3940      +16     
Impacted Files Coverage Δ
boa/src/builtins/symbol/mod.rs 80.13% <79.31%> (-2.98%) ⬇️
boa/src/context.rs 61.45% <100.00%> (+0.65%) ⬆️

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 e775743...3c6e4bd. Read the comment docs.

@joshwd36
Copy link
Contributor

What do you think? @joshwd36

I think this is a good way of doing it, definitely makes getting symbols from the Rust side a lot easier.

@github-actions
Copy link

Benchmark for 2c62562

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 373.2±8.83ns 380.6±20.59ns -1.94%
Arithmetic operations (Full) 266.1±8.59µs 257.9±7.89µs +3.18%
Array access (Execution) 8.6±0.38µs 8.9±0.29µs -3.37%
Array access (Full) 290.4±14.92µs 287.9±12.15µs +0.87%
Array creation (Execution) 3.2±0.10ms 3.4±0.09ms -5.88%
Array creation (Full) 3.5±0.15ms 3.6±0.12ms -2.78%
Array pop (Execution) 1127.7±55.83µs 1228.3±48.02µs -8.19%
Array pop (Full) 1630.1±88.87µs 1652.6±36.07µs -1.36%
Boolean Object Access (Execution) 5.0±0.20µs 5.2±0.25µs -3.85%
Boolean Object Access (Full) 277.4±15.99µs 273.0±11.75µs +1.61%
Clean js (Execution) 749.7±24.66µs 778.4±32.60µs -3.69%
Clean js (Full) 1062.1±37.35µs 1088.3±80.63µs -2.41%
Clean js (Parser) 38.0±1.34µs 38.8±1.93µs -2.06%
Create Realm 508.7±24.64ns 487.3±17.02ns +4.39%
Dynamic Object Property Access (Execution) 5.8±0.49µs 5.9±0.27µs -1.69%
Dynamic Object Property Access (Full) 293.2±34.88µs 277.3±12.03µs +5.73%
Expression (Parser) 7.1±0.35µs 6.9±0.73µs +2.90%
Fibonacci (Execution) 915.5±62.46µs 919.2±32.70µs -0.40%
Fibonacci (Full) 1197.4±30.35µs 1205.8±37.57µs -0.70%
For loop (Execution) 23.7±1.17µs 23.9±0.91µs -0.84%
For loop (Full) 301.8±9.42µs 299.7±10.27µs +0.70%
For loop (Parser) 18.4±0.45µs 18.4±0.59µs 0.00%
Goal Symbols (Parser) 12.6±0.82µs 12.3±0.26µs +2.44%
Hello World (Parser) 3.2±0.09µs 3.2±0.14µs 0.00%
Long file (Parser) 814.8±58.35ns 818.7±42.31ns -0.48%
Mini js (Execution) 672.0±25.97µs 700.8±24.59µs -4.11%
Mini js (Full) 973.8±20.46µs 984.0±45.75µs -1.04%
Mini js (Parser) 34.7±10.39µs 34.0±1.27µs +2.06%
Number Object Access (Execution) 3.9±0.12µs 4.3±0.34µs -9.30%
Number Object Access (Full) 275.8±10.16µs 272.4±10.51µs +1.25%
Object Creation (Execution) 5.1±0.44µs 5.2±0.59µs -1.92%
Object Creation (Full) 279.1±11.59µs 269.7±7.64µs +3.49%
RegExp (Execution) 70.6±3.73µs 71.1±6.37µs -0.70%
RegExp (Full) 363.8±14.28µs 357.1±17.88µs +1.88%
RegExp Literal (Execution) 74.9±2.95µs 74.6±4.51µs +0.40%
RegExp Literal (Full) 358.0±10.65µs 355.0±14.87µs +0.85%
RegExp Literal Creation (Execution) 70.4±3.16µs 70.3±2.46µs +0.14%
RegExp Literal Creation (Full) 352.8±18.80µs 353.1±37.57µs -0.08%
Static Object Property Access (Execution) 5.4±0.97µs 5.3±0.17µs +1.89%
Static Object Property Access (Full) 272.4±11.21µs 275.7±9.64µs -1.20%
String Object Access (Execution) 7.2±0.36µs 7.8±0.49µs -7.69%
String Object Access (Full) 288.1±24.54µs 274.9±10.54µs +4.80%
String comparison (Execution) 6.7±0.22µs 6.7±0.15µs 0.00%
String comparison (Full) 282.4±7.71µs 275.8±10.27µs +2.39%
String concatenation (Execution) 5.5±0.19µs 5.7±0.48µs -3.51%
String concatenation (Full) 276.6±12.19µs 272.1±14.80µs +1.65%
String copy (Execution) 4.2±0.36µs 4.4±0.40µs -4.55%
String copy (Full) 267.7±10.01µs 263.5±7.36µs +1.59%
Symbols (Execution) 3.4±0.15µs 3.5±0.09µs -2.86%
Symbols (Full) 250.8±10.79µs 250.0±11.00µs +0.32%

@github-actions
Copy link

Benchmark for 92935f0

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 423.8±17.90ns 407.3±19.83ns +4.05%
Arithmetic operations (Full) 281.7±9.41µs 287.2±23.92µs -1.92%
Array access (Execution) 9.1±0.34µs 9.5±0.34µs -4.21%
Array access (Full) 310.8±17.86µs 306.2±11.73µs +1.50%
Array creation (Execution) 3.4±0.14ms 3.6±0.11ms -5.56%
Array creation (Full) 3.7±0.07ms 3.8±0.09ms -2.63%
Array pop (Execution) 1195.0±30.47µs 1271.7±48.67µs -6.03%
Array pop (Full) 1724.8±46.79µs 1761.3±53.65µs -2.07%
Boolean Object Access (Execution) 5.4±0.25µs 5.5±0.28µs -1.82%
Boolean Object Access (Full) 300.5±17.72µs 301.5±13.84µs -0.33%
Clean js (Execution) 795.4±26.41µs 814.1±20.77µs -2.30%
Clean js (Full) 1118.5±26.11µs 1148.3±32.20µs -2.60%
Clean js (Parser) 41.3±1.89µs 41.1±1.75µs +0.49%
Create Realm 505.3±18.58ns 506.8±16.43ns -0.30%
Dynamic Object Property Access (Execution) 6.1±0.25µs 6.3±0.20µs -3.17%
Dynamic Object Property Access (Full) 306.2±38.59µs 299.8±8.51µs +2.13%
Expression (Parser) 7.4±0.24µs 7.3±0.23µs +1.37%
Fibonacci (Execution) 997.7±38.41µs 1001.2±39.29µs -0.35%
Fibonacci (Full) 1286.0±48.99µs 1275.2±37.73µs +0.85%
For loop (Execution) 25.3±1.30µs 25.1±0.79µs +0.80%
For loop (Full) 325.3±11.99µs 321.4±14.62µs +1.21%
For loop (Parser) 19.8±1.57µs 19.6±0.95µs +1.02%
Goal Symbols (Parser) 13.1±0.58µs 13.3±0.39µs -1.50%
Hello World (Parser) 3.4±0.20µs 3.3±0.11µs +3.03%
Long file (Parser) 866.2±25.42ns 855.6±38.83ns +1.24%
Mini js (Execution) 717.1±19.58µs 730.8±24.76µs -1.87%
Mini js (Full) 1045.8±62.11µs 1060.0±44.21µs -1.34%
Mini js (Parser) 36.0±1.54µs 36.1±2.06µs -0.28%
Number Object Access (Execution) 4.3±0.19µs 4.4±0.18µs -2.27%
Number Object Access (Full) 291.3±13.68µs 301.5±71.23µs -3.38%
Object Creation (Execution) 5.3±0.23µs 5.5±0.26µs -3.64%
Object Creation (Full) 298.8±9.09µs 291.1±14.63µs +2.65%
RegExp (Execution) 73.3±2.26µs 73.7±2.91µs -0.54%
RegExp (Full) 386.3±10.59µs 389.4±13.37µs -0.80%
RegExp Literal (Execution) 79.6±5.96µs 79.6±4.11µs 0.00%
RegExp Literal (Full) 387.9±12.62µs 381.8±14.53µs +1.60%
RegExp Literal Creation (Execution) 74.8±3.57µs 75.2±2.79µs -0.53%
RegExp Literal Creation (Full) 371.6±11.45µs 376.2±22.93µs -1.22%
Static Object Property Access (Execution) 5.5±0.21µs 5.8±0.27µs -5.17%
Static Object Property Access (Full) 296.9±8.93µs 295.2±8.71µs +0.58%
String Object Access (Execution) 7.9±0.25µs 7.8±0.24µs +1.28%
String Object Access (Full) 302.1±12.79µs 302.1±27.64µs 0.00%
String comparison (Execution) 7.1±0.25µs 7.4±0.36µs -4.05%
String comparison (Full) 300.9±8.77µs 302.5±13.77µs -0.53%
String concatenation (Execution) 5.9±0.29µs 6.0±0.61µs -1.67%
String concatenation (Full) 293.6±9.91µs 293.8±9.60µs -0.07%
String copy (Execution) 4.5±0.14µs 4.9±0.19µs -8.16%
String copy (Full) 290.0±14.40µs 286.6±10.41µs +1.19%
Symbols (Execution) 3.6±0.11µs 3.7±0.15µs -2.70%
Symbols (Full) 271.4±18.64µs 262.6±9.83µs +3.35%

@github-actions
Copy link

Benchmark for ebeb17c

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 382.9±13.49ns 367.5±13.22ns +4.19%
Arithmetic operations (Full) 262.3±10.97µs 263.8±11.44µs -0.57%
Array access (Execution) 9.1±0.50µs 8.7±0.49µs +4.60%
Array access (Full) 285.1±8.76µs 289.1±10.39µs -1.38%
Array creation (Execution) 3.3±0.11ms 3.3±0.11ms 0.00%
Array creation (Full) 3.5±0.08ms 3.5±0.10ms 0.00%
Array pop (Execution) 1149.9±206.90µs 1181.6±40.35µs -2.68%
Array pop (Full) 1648.1±60.66µs 1639.1±98.40µs +0.55%
Boolean Object Access (Execution) 5.0±0.19µs 5.0±0.22µs 0.00%
Boolean Object Access (Full) 277.2±10.64µs 283.3±12.11µs -2.15%
Clean js (Execution) 755.5±36.60µs 762.1±27.87µs -0.87%
Clean js (Full) 1039.6±33.30µs 1061.8±50.41µs -2.09%
Clean js (Parser) 38.0±1.62µs 37.2±1.96µs +2.15%
Create Realm 506.7±29.01ns 465.1±16.19ns +8.94%
Dynamic Object Property Access (Execution) 5.9±0.22µs 5.8±0.28µs +1.72%
Dynamic Object Property Access (Full) 288.4±11.81µs 290.8±14.73µs -0.83%
Expression (Parser) 6.9±0.35µs 6.9±1.10µs 0.00%
Fibonacci (Execution) 969.1±31.02µs 937.3±38.31µs +3.39%
Fibonacci (Full) 1203.7±64.64µs 1231.7±48.21µs -2.27%
For loop (Execution) 25.3±1.14µs 23.4±1.31µs +8.12%
For loop (Full) 299.6±11.81µs 306.8±12.45µs -2.35%
For loop (Parser) 18.2±0.83µs 18.5±0.76µs -1.62%
Goal Symbols (Parser) 12.4±0.67µs 12.3±0.66µs +0.81%
Hello World (Parser) 3.1±0.10µs 3.1±0.19µs 0.00%
Long file (Parser) 783.6±27.51ns 780.5±24.79ns +0.40%
Mini js (Execution) 681.4±22.35µs 684.6±30.59µs -0.47%
Mini js (Full) 983.0±36.15µs 972.6±25.83µs +1.07%
Mini js (Parser) 35.5±1.16µs 33.3±1.56µs +6.61%
Number Object Access (Execution) 3.9±0.15µs 3.9±0.18µs 0.00%
Number Object Access (Full) 280.4±8.72µs 278.8±9.72µs +0.57%
Object Creation (Execution) 5.0±0.20µs 5.1±0.19µs -1.96%
Object Creation (Full) 283.3±11.16µs 277.2±8.88µs +2.20%
RegExp (Execution) 73.9±3.08µs 70.2±3.76µs +5.27%
RegExp (Full) 382.2±13.54µs 362.8±17.15µs +5.35%
RegExp Literal (Execution) 76.1±3.24µs 73.5±3.21µs +3.54%
RegExp Literal (Full) 361.9±10.07µs 356.8±12.18µs +1.43%
RegExp Literal Creation (Execution) 74.6±2.81µs 70.2±7.00µs +6.27%
RegExp Literal Creation (Full) 354.9±14.56µs 351.3±13.89µs +1.02%
Static Object Property Access (Execution) 5.4±0.28µs 5.3±0.28µs +1.89%
Static Object Property Access (Full) 293.3±8.38µs 278.5±10.28µs +5.31%
String Object Access (Execution) 7.4±0.33µs 7.4±0.39µs 0.00%
String Object Access (Full) 284.2±11.32µs 291.0±13.18µs -2.34%
String comparison (Execution) 6.7±0.35µs 6.8±0.23µs -1.47%
String comparison (Full) 292.5±9.51µs 282.8±14.67µs +3.43%
String concatenation (Execution) 5.7±0.26µs 5.7±0.38µs 0.00%
String concatenation (Full) 284.7±9.78µs 273.9±9.68µs +3.94%
String copy (Execution) 4.3±0.17µs 4.3±0.17µs 0.00%
String copy (Full) 287.3±14.90µs 271.4±14.25µs +5.86%
Symbols (Execution) 3.6±0.12µs 3.5±0.14µs +2.86%
Symbols (Full) 247.8±8.41µs 249.2±12.49µs -0.56%

@HalidOdat HalidOdat merged commit 38eaaf4 into master Sep 22, 2020
@HalidOdat HalidOdat deleted the feature/cache-well-known-symbols branch September 22, 2020 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants