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

Remove direct conversion from &str to JsValue/PropertyKey. #3319

Merged
merged 5 commits into from
Sep 29, 2023

Conversation

jedel1043
Copy link
Member

@jedel1043 jedel1043 commented Sep 28, 2023

This is with the objective of avoiding hidden conversions while doing the conversion from a string literal to a JsValue. Removing the direct conversion to JsValue makes it a bit easier to realize that this is doing a costly conversion of
string literal -> (runtime) decode UTF-8 to UTF-16 -> (runtime) JsString -> (runtime) JsValue
and pushes the alternative of using the js_string macro that makes the optimal conversion
string literal -> (compile time) &[u16] -> (runtime) JsString -> (runtime) JsValue

This should technically improve realm initialization times, but let's see what the benchmarks show.

@jedel1043 jedel1043 added API run-benchmark Label used to run banchmarks on PRs labels Sep 28, 2023
@jedel1043 jedel1043 added this to the v0.18.0 milestone Sep 28, 2023
@github-actions
Copy link

github-actions bot commented Sep 28, 2023

Test262 conformance changes

Test result main count PR count difference
Total 95,574 95,574 0
Passed 75,193 75,193 0
Ignored 19,482 19,482 0
Failed 899 899 0
Panics 0 0 0
Conformance 78.68% 78.68% 0.00%

@codecov
Copy link

codecov bot commented Sep 28, 2023

Codecov Report

Attention: 260 lines in your changes are missing coverage. Please review.

Comparison is base (615ae4e) 49.69% compared to head (218c53c) 49.72%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3319      +/-   ##
==========================================
+ Coverage   49.69%   49.72%   +0.03%     
==========================================
  Files         443      443              
  Lines       43167    43378     +211     
==========================================
+ Hits        21451    21569     +118     
- Misses      21716    21809      +93     
Files Coverage Δ
boa_engine/src/builtins/array/array_iterator.rs 81.13% <100.00%> (+0.36%) ⬆️
boa_engine/src/builtins/array/mod.rs 77.16% <100.00%> (+0.06%) ⬆️
boa_engine/src/builtins/array_buffer/mod.rs 10.56% <100.00%> (+0.63%) ⬆️
boa_engine/src/builtins/async_function/mod.rs 39.13% <100.00%> (ø)
boa_engine/src/builtins/async_generator/mod.rs 30.57% <100.00%> (ø)
...ngine/src/builtins/async_generator_function/mod.rs 46.15% <100.00%> (ø)
boa_engine/src/builtins/dataview/mod.rs 12.63% <100.00%> (+1.46%) ⬆️
boa_engine/src/builtins/error/aggregate.rs 22.22% <100.00%> (ø)
boa_engine/src/builtins/error/eval.rs 72.72% <100.00%> (ø)
boa_engine/src/builtins/error/mod.rs 89.58% <100.00%> (ø)
... and 97 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link

Benchmark for 69d2900

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 6.5±0.05ns 7.1±0.00ns +9.23%
Arithmetic operations (Execution) 435.5±1.63ns 440.7±0.78ns +1.19%
Arithmetic operations (Parser) 9.1±0.11µs 8.9±0.23µs -2.20%
Array access (Compiler) 6.5±0.01ns 7.1±0.02ns +9.23%
Array access (Execution) 6.7±14.79µs 6.6±14.15µs -1.49%
Array access (Parser) 15.8±0.32µs 15.9±0.32µs +0.63%
Array creation (Compiler) 6.5±0.04ns 7.1±0.01ns +9.23%
Array creation (Execution) 863.9±1247.58µs 873.4±1422.13µs +1.10%
Array creation (Parser) 19.1±0.36µs 19.7±0.12µs +3.14%
Array pop (Compiler) 6.5±0.02ns 7.1±0.01ns +9.23%
Array pop (Execution) 285.7±256.58µs 287.2±286.76µs +0.53%
Array pop (Parser) 179.7±5.02µs 177.9±2.06µs -1.00%
Boolean Object Access (Compiler) 6.5±0.01ns 7.1±0.00ns +9.23%
Boolean Object Access (Execution) 8.4±33.20µs 5.7±11.15µs -32.14%
Boolean Object Access (Parser) 17.7±0.38µs 18.2±0.08µs +2.82%
Clean js (Compiler) 6.5±0.02ns 7.1±0.02ns +9.23%
Clean js (Execution) 571.3±546.20µs 569.0±445.77µs -0.40%
Clean js (Parser) 46.4±5.43µs 45.0±4.26µs -3.02%
Create Realm 660.2±1988.85µs 581.5±1881.54µs -11.92%
Dynamic Object Property Access (Compiler) 6.5±0.08ns 7.1±0.03ns +9.23%
Dynamic Object Property Access (Execution) 5.5±24.29µs 3.7±6.91µs -32.73%
Dynamic Object Property Access (Parser) 13.9±0.30µs 14.4±0.04µs +3.60%
Fibonacci (Compiler) 6.5±0.01ns 7.1±0.00ns +9.23%
Fibonacci (Execution) 864.9±1286.32µs 1385.5±6049.42µs +60.19%
Fibonacci (Parser) 26.3±44.04µs 22.9±0.13µs -12.93%
For loop (Compiler) 6.5±0.05ns 7.1±0.02ns +9.23%
For loop (Execution) 22.6±59.85µs 62.4±391.19µs +176.11%
For loop (Parser) 20.2±1.60µs 21.0±0.11µs +3.96%
Mini js (Compiler) 6.5±0.03ns 7.1±0.01ns +9.23%
Mini js (Execution) 491.0±1.68µs 496.4±2.90µs +1.10%
Mini js (Parser) 41.3±5.10µs 40.7±6.07µs -1.45%
Number Object Access (Compiler) 6.5±0.02ns 7.1±0.00ns +9.23%
Number Object Access (Execution) 4.3±7.23µs 4.1±6.39µs -4.65%
Number Object Access (Parser) 14.5±0.02µs 14.5±0.31µs 0.00%
Object Creation (Compiler) 6.7±0.04ns 7.1±0.02ns +5.97%
Object Creation (Execution) 4.4±16.99µs 3.2±9.41µs -27.27%
Object Creation (Parser) 12.2±0.21µs 11.9±0.34µs -2.46%
RegExp (Compiler) 6.5±0.01ns 7.1±0.01ns +9.23%
RegExp (Execution) 17.9±49.48µs 14.7±19.89µs -17.88%
RegExp (Parser) 13.2±0.31µs 12.7±0.36µs -3.79%
RegExp Creation (Compiler) 6.5±0.15ns 7.1±0.01ns +9.23%
RegExp Creation (Execution) 19.5±126.77µs 7.7±13.45µs -60.51%
RegExp Creation (Parser) 10.8±0.14µs 11.4±0.18µs +5.56%
RegExp Literal (Compiler) 6.5±0.01ns 7.1±0.03ns +9.23%
RegExp Literal (Execution) 14.8±19.98µs 12.7±13.53µs -14.19%
RegExp Literal (Parser) 20.8±58.46µs 14.9±0.10µs -28.37%
RegExp Literal Creation (Compiler) 6.5±0.01ns 7.1±0.02ns +9.23%
RegExp Literal Creation (Execution) 8.7±10.12µs 6.5±7.73µs -25.29%
RegExp Literal Creation (Parser) 12.8±0.22µs 12.7±0.16µs -0.78%
Static Object Property Access (Compiler) 6.6±0.29ns 7.1±0.00ns +7.58%
Static Object Property Access (Execution) 3.2±7.28µs 3.3±7.61µs +3.12%
Static Object Property Access (Parser) 12.8±0.27µs 13.0±0.28µs +1.56%
String Object Access (Compiler) 6.5±0.01ns 7.1±0.03ns +9.23%
String Object Access (Execution) 6.7±9.49µs 10.2±38.93µs +52.24%
String Object Access (Parser) 17.4±0.61µs 17.7±0.03µs +1.72%
String comparison (Compiler) 6.6±0.00ns 7.1±0.02ns +7.58%
String comparison (Execution) 3.1±7.58µs 3.5±9.99µs +12.90%
String comparison (Parser) 18.5±4.47µs 17.1±2.56µs -7.57%
String concatenation (Compiler) 6.5±0.01ns 7.1±0.07ns +9.23%
String concatenation (Execution) 2.5±5.71µs 2.7±6.69µs +8.00%
String concatenation (Parser) 11.6±1.93µs 10.9±0.35µs -6.03%
String copy (Compiler) 6.5±0.05ns 7.1±0.00ns +9.23%
String copy (Execution) 2.5±6.51µs 2.8±8.20µs +12.00%
String copy (Parser) 7.7±0.18µs 30.3±215.00µs +293.51%
Symbols (Compiler) 6.6±0.06ns 7.2±0.28ns +9.09%
Symbols (Execution) 1265.4±585.65ns 1199.1±107.76ns -5.24%
Symbols (Parser) 6.1±0.16µs 6.0±0.14µs -1.64%

@jedel1043
Copy link
Member Author

Ok, results are a bit erratic (+293.51% in parsing string copy without even touching boa_parser???), so I'll run them locally.

@jedel1043 jedel1043 removed the run-benchmark Label used to run banchmarks on PRs label Sep 28, 2023
@jedel1043
Copy link
Member Author

Yep, some nice wins by skipping the conversions.
While main uses 600KB of data:

image

This PR uses 573KB:

image

Mainly because conversions use an additional 24KB of intermediary allocations:

image

It would be cool if we could also remove the additional 12KB used by the thread local cache of static strings (maybe a phf?):

image

@jedel1043 jedel1043 requested a review from a team September 28, 2023 18:17
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.

I really like the change. The cost of conversions like this should be very clear.

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.

I like this! I am a bit curious about documentation on using js_string over &str for contributors and anybody consuming the API. But I'm fine with merging as is.

@nekevss nekevss added this pull request to the merge queue Sep 29, 2023
Merged via the queue into main with commit b80409d Sep 29, 2023
10 checks passed
@HalidOdat HalidOdat deleted the only-js-string branch September 29, 2023 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants