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

Extracted __proto__ from internal slots #580

Merged
merged 1 commit into from
Jul 20, 2020

Conversation

HalidOdat
Copy link
Member

This Pull Request fixes/closes #578 .

@HalidOdat HalidOdat added performance Performance related changes and issues technical debt execution Issues or PRs related to code execution labels Jul 20, 2020
@HalidOdat HalidOdat added this to the v0.10.0 milestone Jul 20, 2020
@codecov
Copy link

codecov bot commented Jul 20, 2020

Codecov Report

Merging #580 into master will decrease coverage by 0.05%.
The diff coverage is 71.79%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #580      +/-   ##
==========================================
- Coverage   70.40%   70.34%   -0.06%     
==========================================
  Files         175      175              
  Lines       11162    11160       -2     
==========================================
- Hits         7859     7851       -8     
- Misses       3303     3309       +6     
Impacted Files Coverage Δ
boa/src/builtins/json/tests.rs 100.00% <ø> (ø)
boa/src/builtins/string/tests.rs 100.00% <ø> (ø)
boa/src/builtins/value/conversions.rs 57.53% <0.00%> (-2.47%) ⬇️
boa/src/builtins/value/display.rs 75.94% <ø> (+0.04%) ⬆️
boa/src/syntax/parser/tests.rs 100.00% <ø> (ø)
boa/src/builtins/object/mod.rs 41.09% <53.33%> (+0.42%) ⬆️
boa/src/builtins/value/mod.rs 68.29% <66.66%> (-0.33%) ⬇️
boa/src/builtins/array/mod.rs 80.97% <100.00%> (ø)
boa/src/builtins/boolean/tests.rs 100.00% <100.00%> (ø)
boa/src/builtins/function/mod.rs 71.25% <100.00%> (-0.51%) ⬇️
... and 7 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 08a608a...875b291. Read the comment docs.

@github-actions
Copy link

Benchmark for ba450bc

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 386.4±38.12ns 369.6±12.06ns +4.55%
Arithmetic operations (Full) 164.5±5.21µs 176.8±6.17µs -6.96%
Array access (Execution) 14.0±0.61µs 14.5±0.53µs -3.45%
Array access (Full) 193.9±10.94µs 198.7±6.19µs -2.42%
Array creation (Execution) 3.8±0.14ms 3.9±0.11ms -2.56%
Array creation (Full) 4.2±0.10ms 4.3±0.18ms -2.33%
Array pop (Execution) 1477.4±69.87µs 1488.4±57.63µs -0.74%
Array pop (Full) 1808.1±75.74µs 1807.4±44.95µs +0.04%
Boolean Object Access (Execution) 4.4±0.15µs 5.3±0.14µs -16.98%
Boolean Object Access (Full) 173.3±4.75µs 187.7±6.33µs -7.67%
Create Realm 148.2±6.81µs 161.4±7.53µs -8.18%
Dynamic Object Property Access (Execution) 6.8±1.13µs 7.3±0.28µs -6.85%
Dynamic Object Property Access (Full) 178.8±4.67µs 186.4±4.38µs -4.08%
Expression (Lexer) 2.4±0.15µs 2.4±0.06µs 0.00%
Expression (Parser) 5.3±0.28µs 5.4±0.17µs -1.85%
Fibonacci (Execution) 997.3±52.69µs 1021.5±84.98µs -2.37%
Fibonacci (Full) 1183.0±49.30µs 1225.6±35.29µs -3.48%
For loop (Execution) 23.2±2.29µs 23.3±0.68µs -0.43%
For loop (Full) 200.4±10.40µs 203.6±10.19µs -1.57%
For loop (Lexer) 5.2±0.23µs 5.2±0.22µs 0.00%
For loop (Parser) 13.7±0.54µs 14.1±1.19µs -2.84%
Goal Symbols (Parser) 8.4±0.48µs 8.3±0.23µs +1.20%
Hello World (Lexer) 823.0±42.31ns 831.4±76.14ns -1.01%
Hello World (Parser) 2.1±0.08µs 2.2±0.10µs -4.55%
Long file (Parser) 6.3±0.20ms 6.3±0.15ms 0.00%
Number Object Access (Execution) 3.5±0.11µs 4.2±0.26µs -16.67%
Number Object Access (Full) 173.3±7.55µs 184.5±7.78µs -6.07%
Object Creation (Execution) 5.6±0.21µs 6.3±0.22µs -11.11%
Object Creation (Full) 199.8±7.86µs 205.7±10.96µs -2.87%
RegExp (Execution) 65.0±2.65µs 68.4±3.58µs -4.97%
RegExp (Full) 291.1±13.58µs 300.8±7.17µs -3.22%
RegExp Literal (Execution) 70.5±3.57µs 70.5±2.28µs 0.00%
RegExp Literal (Full) 248.8±8.17µs 267.9±12.61µs -7.13%
RegExp Literal Creation (Execution) 64.8±2.47µs 67.8±3.47µs -4.42%
RegExp Literal Creation (Full) 301.4±17.56µs 296.2±8.57µs +1.76%
Static Object Property Access (Execution) 5.9±0.31µs 6.6±0.32µs -10.61%
Static Object Property Access (Full) 173.2±9.16µs 192.6±13.82µs -10.07%
String Object Access (Execution) 7.9±0.23µs 9.1±0.21µs -13.19%
String Object Access (Full) 179.1±19.25µs 189.9±4.83µs -5.69%
String comparison (Execution) 6.5±0.30µs 6.9±0.22µs -5.80%
String comparison (Full) 177.5±19.51µs 189.4±9.07µs -6.28%
String concatenation (Execution) 5.6±0.59µs 5.9±0.19µs -5.08%
String concatenation (Full) 168.7±6.87µs 184.6±5.65µs -8.61%
String copy (Execution) 4.4±0.21µs 4.8±0.48µs -8.33%
String copy (Full) 171.9±10.02µs 179.3±7.63µs -4.13%
Symbols (Execution) 3.7±0.20µs 4.2±0.12µs -11.90%
Symbols (Full) 167.6±8.18µs 172.4±7.83µs -2.78%

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 very good, this is a much needed change and benchmarks are looking great! Maybe we could extend this to other things in the future too :)

Check my comments, I have a couple of suggestions that might improve it.

boa/src/builtins/array/mod.rs Outdated Show resolved Hide resolved
.get_binding_value("Array")
.expect("Array was not initialized")
.borrow()
.get_field(PROTOTYPE);
Copy link
Member

Choose a reason for hiding this comment

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

We could have a prototype() getter here, and the get_field() use that function if the passed string is the correct one. I think this would make it faster most of the time.

Copy link
Member Author

@HalidOdat HalidOdat Jul 20, 2020

Choose a reason for hiding this comment

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

I think we could store the builtin objects like Array, String, Number etc, in the interpreter or Realm as fields as a GcObject this will eliminate the Object lookup an we could do something like:

interperter.realm().array_object().prototype()

So we would cache the them, this will probably be easier after #577

boa/src/builtins/boolean/tests.rs Show resolved Hide resolved
boa/src/builtins/object/mod.rs Outdated Show resolved Hide resolved
@@ -130,6 +133,7 @@ impl Object {
internal_slots: FxHashMap::default(),
properties: FxHashMap::default(),
symbol_properties: FxHashMap::default(),
prototype: Value::null(),
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm I see many fields here have the default value. Can't we use the ..Self::default() notation?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can use the ..Self::default() notation but, eventually we will have to remove them they are not spec compliant.


new_func.prototype = function_prototype.clone();
Copy link
Member

Choose a reason for hiding this comment

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

Here I see we create a function and then assign it a prototype. I would do this with a set_prototype() setter as I explained before, but if we are using this a lot, we could maybe have a constructor that accepts a prototype too.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is probably better for the constructor to take it, function objects should always have a prototype instance.

boa/src/exec/new/mod.rs Outdated Show resolved Hide resolved
boa/src/exec/tests.rs Show resolved Hide resolved
@HalidOdat
Copy link
Member Author

HalidOdat commented Jul 20, 2020

Maybe we could extend this to other things in the future too :)

Yes. I planing to deprecate the intenal_slots I already did this for extensible and now __proto__ and in a future PR I will remove it entirely, should shrink the size of Object too :)

@github-actions
Copy link

Benchmark for e07b64c

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 380.3±9.14ns 388.3±19.30ns -2.06%
Arithmetic operations (Full) 178.5±6.54µs 183.3±6.73µs -2.62%
Array access (Execution) 14.5±0.51µs 15.7±0.69µs -7.64%
Array access (Full) 199.0±9.48µs 204.7±8.35µs -2.78%
Array creation (Execution) 3.9±0.11ms 4.0±0.08ms -2.50%
Array creation (Full) 4.4±0.12ms 4.3±0.08ms +2.33%
Array pop (Execution) 1561.5±58.96µs 1559.5±51.12µs +0.13%
Array pop (Full) 1910.2±64.26µs 1886.5±68.25µs +1.26%
Boolean Object Access (Execution) 4.6±0.16µs 5.6±0.21µs -17.86%
Boolean Object Access (Full) 185.1±19.98µs 191.6±5.08µs -3.39%
Create Realm 160.6±5.06µs 172.0±9.06µs -6.63%
Dynamic Object Property Access (Execution) 6.8±0.21µs 7.8±0.39µs -12.82%
Dynamic Object Property Access (Full) 188.2±6.91µs 197.5±7.14µs -4.71%
Expression (Lexer) 2.5±0.06µs 2.5±0.10µs 0.00%
Expression (Parser) 5.5±0.15µs 5.6±0.34µs -1.79%
Fibonacci (Execution) 1030.7±35.34µs 1056.9±40.91µs -2.48%
Fibonacci (Full) 1242.8±38.94µs 1291.5±51.57µs -3.77%
For loop (Execution) 23.2±1.04µs 24.2±1.12µs -4.13%
For loop (Full) 201.7±8.25µs 210.4±10.47µs -4.13%
For loop (Lexer) 5.6±0.22µs 5.6±0.16µs 0.00%
For loop (Parser) 14.4±0.48µs 14.5±1.30µs -0.69%
Goal Symbols (Parser) 8.6±0.28µs 8.6±0.26µs 0.00%
Hello World (Lexer) 895.9±39.80ns 848.9±22.50ns +5.54%
Hello World (Parser) 2.2±0.07µs 2.2±0.07µs 0.00%
Long file (Parser) 6.5±0.13ms 6.5±0.11ms 0.00%
Number Object Access (Execution) 3.6±0.15µs 4.4±0.28µs -18.18%
Number Object Access (Full) 184.1±9.50µs 192.5±11.07µs -4.36%
Object Creation (Execution) 5.9±0.25µs 6.8±0.24µs -13.24%
Object Creation (Full) 209.8±11.86µs 212.3±7.61µs -1.18%
RegExp (Execution) 70.3±2.20µs 72.6±4.69µs -3.17%
RegExp (Full) 268.4±8.34µs 281.1±11.37µs -4.52%
RegExp Literal (Execution) 74.8±3.87µs 75.2±2.51µs -0.53%
RegExp Literal (Full) 267.8±9.91µs 273.2±9.65µs -1.98%
RegExp Literal Creation (Execution) 70.7±2.90µs 71.4±3.06µs -0.98%
RegExp Literal Creation (Full) 310.7±12.82µs 311.2±12.53µs -0.16%
Static Object Property Access (Execution) 6.2±0.42µs 6.9±0.18µs -10.14%
Static Object Property Access (Full) 186.8±4.79µs 194.2±9.01µs -3.81%
String Object Access (Execution) 8.6±0.38µs 9.6±0.23µs -10.42%
String Object Access (Full) 188.3±2.93µs 200.4±15.68µs -6.04%
String comparison (Execution) 6.9±0.26µs 7.5±0.49µs -8.00%
String comparison (Full) 187.3±9.64µs 198.7±12.48µs -5.74%
String concatenation (Execution) 5.8±0.28µs 6.3±0.29µs -7.94%
String concatenation (Full) 182.0±6.40µs 195.4±13.10µs -6.86%
String copy (Execution) 4.6±0.48µs 5.0±0.18µs -8.00%
String copy (Full) 178.5±6.20µs 187.6±6.69µs -4.85%
Symbols (Execution) 3.8±0.14µs 4.4±0.18µs -13.64%
Symbols (Full) 173.6±5.62µs 181.4±7.06µs -4.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.

Perfect :)

@HalidOdat HalidOdat merged commit d8eb7ca into master Jul 20, 2020
@HalidOdat HalidOdat deleted the extract-prototype-instance branch July 20, 2020 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
execution Issues or PRs related to code execution performance Performance related changes and issues technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extract prototype from internal slots
2 participants