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] - Feature JsFunction #2015

Closed
wants to merge 1 commit into from
Closed

Conversation

HalidOdat
Copy link
Member

@HalidOdat HalidOdat commented Apr 7, 2022

This PR adds JsFunction wrapper around JavaScript Function object, like #1746
With this PR we can distinguish between regular object and function object when we need, such as accessors (because they always need to be functions), predicates in JsArray methods like map, find, etc. With this abstraction we leverage the type system of rust which cleans the API making intentions clear.

It changes the following:

  • Make methods that take predicate/callback function take JsFunctions
  • Make .accessor() and .static_accessor() take Option<JsFunction>
  • Make FunctionBuilder return JsFunction
  • Make ConstructorBuilder return JsFunction
  • Make ClassBuilder return JsFunction

@HalidOdat HalidOdat added enhancement New feature or request API labels Apr 7, 2022
@HalidOdat HalidOdat added this to the v0.15.0 milestone Apr 7, 2022
@github-actions
Copy link

github-actions bot commented Apr 7, 2022

Test262 conformance changes

VM implementation

Test result main count PR count difference
Total 89,014 89,014 0
Passed 53,264 53,264 0
Ignored 22,149 22,149 0
Failed 13,601 13,601 0
Panics 0 0 0
Conformance 59.84% 59.84% 0.00%

@codecov
Copy link

codecov bot commented Apr 7, 2022

Codecov Report

Merging #2015 (257097b) into main (3226e54) will decrease coverage by 0.01%.
The diff coverage is 26.08%.

@@            Coverage Diff             @@
##             main    #2015      +/-   ##
==========================================
- Coverage   43.86%   43.85%   -0.02%     
==========================================
  Files         212      213       +1     
  Lines       18758    18767       +9     
==========================================
+ Hits         8229     8231       +2     
- Misses      10529    10536       +7     
Impacted Files Coverage Δ
boa_engine/src/class.rs 0.00% <0.00%> (ø)
boa_engine/src/object/jsarray.rs 5.15% <0.00%> (ø)
boa_engine/src/object/jstypedarray.rs 0.00% <0.00%> (ø)
boa_engine/src/object/jsfunction.rs 9.09% <9.09%> (ø)
boa_engine/src/builtins/intl/date_time_format.rs 12.50% <50.00%> (ø)
boa_engine/src/object/mod.rs 21.22% <75.00%> (+0.13%) ⬆️
boa_engine/src/builtins/array/mod.rs 75.70% <100.00%> (ø)
boa_engine/src/syntax/lexer/template.rs 36.36% <0.00%> (-2.77%) ⬇️
boa_engine/src/environments/compile.rs 40.70% <0.00%> (+0.88%) ⬆️
boa_engine/src/realm.rs 40.00% <0.00%> (+6.66%) ⬆️

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 3226e54...257097b. Read the comment docs.

@github-actions
Copy link

github-actions bot commented Apr 7, 2022

Benchmark for e45f1fd

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 518.8±0.88ns 525.4±0.93ns +1.27%
Arithmetic operations (Execution) 646.2±1.28ns 645.8±1.82ns -0.06%
Arithmetic operations (Parser) 5.9±0.03µs 5.9±0.01µs 0.00%
Array access (Compiler) 1293.0±3.37ns 1279.1±2.79ns -1.08%
Array access (Execution) 7.8±0.06µs 7.7±0.02µs -1.28%
Array access (Parser) 12.6±0.02µs 12.6±0.02µs 0.00%
Array creation (Compiler) 1846.8±11.88ns 1806.3±4.66ns -2.19%
Array creation (Execution) 2.6±0.00ms 2.5±0.00ms -3.85%
Array creation (Parser) 14.5±0.02µs 14.4±0.02µs -0.69%
Array pop (Compiler) 3.8±0.01µs 3.7±0.01µs -2.63%
Array pop (Execution) 1130.1±2.93µs 1109.8±3.34µs -1.80%
Array pop (Parser) 144.0±0.18µs 144.4±0.13µs +0.28%
Boolean Object Access (Compiler) 1058.0±1.91ns 1054.3±0.77ns -0.35%
Boolean Object Access (Execution) 4.1±0.01µs 4.2±0.01µs +2.44%
Boolean Object Access (Parser) 15.1±0.01µs 15.2±0.01µs +0.66%
Clean js (Compiler) 3.3±0.01µs 3.4±0.01µs +3.03%
Clean js (Execution) 684.1±3.15µs 691.2±6.31µs +1.04%
Clean js (Parser) 31.4±0.03µs 31.0±0.03µs -1.27%
Create Realm 297.6±0.34ns 275.7±0.22ns -7.36%
Dynamic Object Property Access (Compiler) 1638.8±3.03ns 1625.9±3.98ns -0.79%
Dynamic Object Property Access (Execution) 5.4±0.01µs 5.4±0.01µs 0.00%
Dynamic Object Property Access (Parser) 11.3±0.02µs 11.2±0.01µs -0.88%
Fibonacci (Compiler) 2.3±0.01µs 2.3±0.01µs 0.00%
Fibonacci (Execution) 1329.8±1.26µs 1358.1±2.29µs +2.13%
Fibonacci (Parser) 17.2±0.02µs 17.0±0.03µs -1.16%
For loop (Compiler) 1949.1±6.89ns 1932.7±6.50ns -0.84%
For loop (Execution) 15.2±0.06µs 15.2±0.05µs 0.00%
For loop (Parser) 14.8±0.03µs 14.7±0.02µs -0.68%
Mini js (Compiler) 3.2±0.01µs 3.3±0.01µs +3.12%
Mini js (Execution) 649.4±3.74µs 653.9±4.50µs +0.69%
Mini js (Parser) 27.6±0.05µs 27.2±0.11µs -1.45%
Number Object Access (Compiler) 1026.8±1.75ns 1019.9±2.01ns -0.67%
Number Object Access (Execution) 3.2±0.02µs 3.3±0.01µs +3.12%
Number Object Access (Parser) 12.0±0.21µs 11.9±0.05µs -0.83%
Object Creation (Compiler) 1403.7±2.63ns 1383.5±4.41ns -1.44%
Object Creation (Execution) 5.1±0.02µs 5.0±0.02µs -1.96%
Object Creation (Parser) 9.7±0.01µs 9.7±0.02µs 0.00%
RegExp (Compiler) 1637.2±4.25ns 1609.7±6.10ns -1.68%
RegExp (Execution) 11.5±0.06µs 11.1±0.05µs -3.48%
RegExp (Parser) 10.7±0.02µs 10.8±0.02µs +0.93%
RegExp Creation (Compiler) 1418.1±3.46ns 1410.9±2.24ns -0.51%
RegExp Creation (Execution) 8.7±0.03µs 8.3±0.03µs -4.60%
RegExp Creation (Parser) 8.9±0.02µs 9.0±0.02µs +1.12%
RegExp Literal (Compiler) 1635.5±3.81ns 1623.1±15.70ns -0.76%
RegExp Literal (Execution) 11.5±0.07µs 11.2±0.07µs -2.61%
RegExp Literal (Parser) 8.7±0.02µs 8.7±0.03µs 0.00%
RegExp Literal Creation (Compiler) 1413.4±1.38ns 1429.7±3.96ns +1.15%
RegExp Literal Creation (Execution) 8.7±0.04µs 8.3±0.02µs -4.60%
RegExp Literal Creation (Parser) 6.8±0.01µs 6.8±0.02µs 0.00%
Static Object Property Access (Compiler) 1413.5±1.41ns 1439.5±9.75ns +1.84%
Static Object Property Access (Execution) 5.2±0.01µs 5.3±0.01µs +1.92%
Static Object Property Access (Parser) 10.5±0.04µs 10.5±0.02µs 0.00%
String Object Access (Compiler) 1434.0±9.59ns 1420.0±4.07ns -0.98%
String Object Access (Execution) 6.0±0.04µs 6.0±0.02µs 0.00%
String Object Access (Parser) 14.9±0.01µs 14.9±0.05µs 0.00%
String comparison (Compiler) 2.1±0.00µs 2.1±0.01µs 0.00%
String comparison (Execution) 4.6±0.01µs 4.5±0.01µs -2.17%
String comparison (Parser) 11.8±0.02µs 11.8±0.02µs 0.00%
String concatenation (Compiler) 1666.0±15.54ns 1637.4±3.92ns -1.72%
String concatenation (Execution) 4.3±0.02µs 4.3±0.01µs 0.00%
String concatenation (Parser) 8.1±0.02µs 8.1±0.03µs 0.00%
String copy (Compiler) 1340.2±5.68ns 1297.1±4.37ns -3.22%
String copy (Execution) 4.1±0.01µs 4.1±0.02µs 0.00%
String copy (Parser) 6.1±0.01µs 6.0±0.02µs -1.64%
Symbols (Compiler) 927.2±4.14ns 937.1±3.49ns +1.07%
Symbols (Execution) 4.1±0.02µs 4.2±0.01µs +2.44%
Symbols (Parser) 4.5±0.00µs 4.6±0.01µs +2.22%

@HalidOdat HalidOdat force-pushed the feature/jsfunction branch from 6673621 to 47fbfba Compare April 8, 2022 03:10
@github-actions
Copy link

github-actions bot commented Apr 8, 2022

Benchmark for 396ad57

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 520.7±0.83ns 513.6±0.73ns -1.36%
Arithmetic operations (Execution) 647.6±0.73ns 642.0±1.48ns -0.86%
Arithmetic operations (Parser) 5.8±0.01µs 5.8±0.01µs 0.00%
Array access (Compiler) 1282.1±4.01ns 1309.8±4.57ns +2.16%
Array access (Execution) 7.8±0.02µs 7.7±0.02µs -1.28%
Array access (Parser) 12.6±0.01µs 12.7±0.02µs +0.79%
Array creation (Compiler) 1815.6±4.41ns 1812.8±4.39ns -0.15%
Array creation (Execution) 2.6±0.00ms 2.5±0.00ms -3.85%
Array creation (Parser) 14.3±0.03µs 14.4±0.02µs +0.70%
Array pop (Compiler) 3.8±0.01µs 3.6±0.01µs -5.26%
Array pop (Execution) 1134.9±3.93µs 1112.0±3.29µs -2.02%
Array pop (Parser) 144.0±0.17µs 144.6±0.09µs +0.42%
Boolean Object Access (Compiler) 1079.3±5.42ns 1048.6±2.71ns -2.84%
Boolean Object Access (Execution) 4.2±0.01µs 4.2±0.01µs 0.00%
Boolean Object Access (Parser) 15.1±0.02µs 15.2±0.02µs +0.66%
Clean js (Compiler) 3.4±0.01µs 3.4±0.01µs 0.00%
Clean js (Execution) 687.2±3.12µs 689.0±4.10µs +0.26%
Clean js (Parser) 31.0±0.03µs 30.8±0.03µs -0.65%
Create Realm 287.3±3.16ns 273.9±0.42ns -4.66%
Dynamic Object Property Access (Compiler) 1656.8±3.37ns 1625.0±4.02ns -1.92%
Dynamic Object Property Access (Execution) 5.4±0.01µs 5.4±0.01µs 0.00%
Dynamic Object Property Access (Parser) 11.2±0.03µs 11.3±0.02µs +0.89%
Fibonacci (Compiler) 2.3±0.01µs 2.3±0.01µs 0.00%
Fibonacci (Execution) 1338.4±1.44µs 1331.5±3.08µs -0.52%
Fibonacci (Parser) 17.1±0.03µs 17.1±0.04µs 0.00%
For loop (Compiler) 1976.1±9.91ns 1979.1±10.74ns +0.15%
For loop (Execution) 15.2±0.04µs 15.3±0.05µs +0.66%
For loop (Parser) 14.7±0.03µs 14.6±0.03µs -0.68%
Mini js (Compiler) 3.2±0.01µs 3.3±0.01µs +3.12%
Mini js (Execution) 650.2±3.91µs 649.1±3.81µs -0.17%
Mini js (Parser) 27.5±0.05µs 27.1±0.04µs -1.45%
Number Object Access (Compiler) 1039.9±1.46ns 1021.5±2.21ns -1.77%
Number Object Access (Execution) 3.2±0.02µs 3.3±0.03µs +3.12%
Number Object Access (Parser) 11.8±0.01µs 11.8±0.01µs 0.00%
Object Creation (Compiler) 1388.3±3.85ns 1412.5±7.40ns +1.74%
Object Creation (Execution) 5.0±0.01µs 5.1±0.02µs +2.00%
Object Creation (Parser) 9.7±0.02µs 9.8±0.01µs +1.03%
RegExp (Compiler) 1663.3±3.05ns 1636.0±9.53ns -1.64%
RegExp (Execution) 11.6±0.08µs 11.0±0.06µs -5.17%
RegExp (Parser) 10.7±0.02µs 10.8±0.08µs +0.93%
RegExp Creation (Compiler) 1435.7±2.97ns 1430.6±4.39ns -0.36%
RegExp Creation (Execution) 8.6±0.04µs 8.3±0.03µs -3.49%
RegExp Creation (Parser) 8.9±0.02µs 9.0±0.10µs +1.12%
RegExp Literal (Compiler) 1657.2±4.17ns 1617.2±5.06ns -2.41%
RegExp Literal (Execution) 11.6±0.06µs 11.1±0.05µs -4.31%
RegExp Literal (Parser) 8.7±0.02µs 8.7±0.02µs 0.00%
RegExp Literal Creation (Compiler) 1416.9±1.91ns 1392.5±2.95ns -1.72%
RegExp Literal Creation (Execution) 8.7±0.03µs 8.3±0.02µs -4.60%
RegExp Literal Creation (Parser) 6.9±0.02µs 6.9±0.02µs 0.00%
Static Object Property Access (Compiler) 1425.5±2.88ns 1414.1±6.09ns -0.80%
Static Object Property Access (Execution) 5.2±0.01µs 5.3±0.01µs +1.92%
Static Object Property Access (Parser) 10.4±0.02µs 10.5±0.02µs +0.96%
String Object Access (Compiler) 1443.4±6.65ns 1433.8±8.38ns -0.67%
String Object Access (Execution) 5.8±0.02µs 6.0±0.02µs +3.45%
String Object Access (Parser) 15.0±0.01µs 14.9±0.09µs -0.67%
String comparison (Compiler) 2.1±0.00µs 2.1±0.00µs 0.00%
String comparison (Execution) 4.6±0.01µs 4.5±0.01µs -2.17%
String comparison (Parser) 11.9±0.04µs 11.5±0.01µs -3.36%
String concatenation (Compiler) 1670.3±2.65ns 1639.8±5.00ns -1.83%
String concatenation (Execution) 4.3±0.02µs 4.4±0.09µs +2.33%
String concatenation (Parser) 8.2±0.03µs 7.9±0.02µs -3.66%
String copy (Compiler) 1317.8±4.35ns 1287.0±3.22ns -2.34%
String copy (Execution) 4.1±0.01µs 4.1±0.01µs 0.00%
String copy (Parser) 6.1±0.02µs 5.9±0.02µs -3.28%
Symbols (Compiler) 941.3±2.33ns 922.4±3.65ns -2.01%
Symbols (Execution) 4.1±0.02µs 4.2±0.01µs +2.44%
Symbols (Parser) 4.6±0.01µs 4.6±0.01µs 0.00%

@HalidOdat HalidOdat force-pushed the feature/jsfunction branch from 47fbfba to 1396564 Compare April 8, 2022 13:48
@github-actions
Copy link

github-actions bot commented Apr 8, 2022

Benchmark for 7efac74

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 508.1±0.80ns 516.8±2.89ns +1.71%
Arithmetic operations (Execution) 674.6±1.02ns 653.2±2.34ns -3.17%
Arithmetic operations (Parser) 5.8±0.00µs 5.9±0.01µs +1.72%
Array access (Compiler) 1271.4±2.84ns 1290.7±3.50ns +1.52%
Array access (Execution) 7.8±0.03µs 7.6±0.01µs -2.56%
Array access (Parser) 12.6±0.03µs 12.6±0.01µs 0.00%
Array creation (Compiler) 1790.4±4.25ns 1824.5±5.02ns +1.90%
Array creation (Execution) 2.6±0.00ms 2.5±0.00ms -3.85%
Array creation (Parser) 14.3±0.02µs 14.3±0.04µs 0.00%
Array pop (Compiler) 3.6±0.01µs 3.8±0.01µs +5.56%
Array pop (Execution) 1129.6±3.05µs 1115.2±3.15µs -1.27%
Array pop (Parser) 143.5±0.13µs 144.4±0.22µs +0.63%
Boolean Object Access (Compiler) 1051.2±1.67ns 1057.1±2.07ns +0.56%
Boolean Object Access (Execution) 4.2±0.04µs 4.1±0.01µs -2.38%
Boolean Object Access (Parser) 15.2±0.07µs 14.9±0.01µs -1.97%
Clean js (Compiler) 3.3±0.01µs 3.4±0.02µs +3.03%
Clean js (Execution) 691.8±3.53µs 687.4±4.39µs -0.64%
Clean js (Parser) 30.8±0.06µs 30.8±0.05µs 0.00%
Create Realm 271.3±0.18ns 283.8±0.18ns +4.61%
Dynamic Object Property Access (Compiler) 1589.8±3.17ns 1621.0±6.16ns +1.96%
Dynamic Object Property Access (Execution) 5.4±0.02µs 5.3±0.01µs -1.85%
Dynamic Object Property Access (Parser) 11.2±0.01µs 11.2±0.03µs 0.00%
Fibonacci (Compiler) 2.3±0.01µs 2.3±0.01µs 0.00%
Fibonacci (Execution) 1344.1±1.33µs 1343.0±5.23µs -0.08%
Fibonacci (Parser) 17.3±0.04µs 16.9±0.03µs -2.31%
For loop (Compiler) 1924.8±7.67ns 1958.9±9.55ns +1.77%
For loop (Execution) 15.2±0.04µs 15.2±0.05µs 0.00%
For loop (Parser) 14.5±0.02µs 14.6±0.02µs +0.69%
Mini js (Compiler) 3.2±0.01µs 3.3±0.01µs +3.12%
Mini js (Execution) 654.5±4.02µs 651.6±4.45µs -0.44%
Mini js (Parser) 27.3±0.04µs 27.2±0.03µs -0.37%
Number Object Access (Compiler) 1009.4±2.29ns 1016.7±1.43ns +0.72%
Number Object Access (Execution) 3.2±0.01µs 3.2±0.01µs 0.00%
Number Object Access (Parser) 11.8±0.02µs 11.7±0.11µs -0.85%
Object Creation (Compiler) 1376.4±3.46ns 1372.7±3.57ns -0.27%
Object Creation (Execution) 5.1±0.02µs 5.0±0.01µs -1.96%
Object Creation (Parser) 9.7±0.01µs 9.7±0.02µs 0.00%
RegExp (Compiler) 1642.7±11.23ns 1634.3±2.97ns -0.51%
RegExp (Execution) 11.1±0.06µs 11.3±0.06µs +1.80%
RegExp (Parser) 10.7±0.02µs 10.6±0.02µs -0.93%
RegExp Creation (Compiler) 1402.8±17.81ns 1426.4±2.72ns +1.68%
RegExp Creation (Execution) 8.3±0.02µs 8.7±0.03µs +4.82%
RegExp Creation (Parser) 8.9±0.06µs 8.9±0.04µs 0.00%
RegExp Literal (Compiler) 1624.4±8.25ns 1629.4±7.27ns +0.31%
RegExp Literal (Execution) 11.1±0.06µs 11.3±0.05µs +1.80%
RegExp Literal (Parser) 8.6±0.02µs 8.7±0.02µs +1.16%
RegExp Literal Creation (Compiler) 1403.9±4.26ns 1426.4±2.64ns +1.60%
RegExp Literal Creation (Execution) 8.3±0.03µs 8.7±0.03µs +4.82%
RegExp Literal Creation (Parser) 6.8±0.01µs 6.8±0.01µs 0.00%
Static Object Property Access (Compiler) 1435.8±2.70ns 1410.3±3.08ns -1.78%
Static Object Property Access (Execution) 5.3±0.04µs 5.2±0.01µs -1.89%
Static Object Property Access (Parser) 10.4±0.02µs 10.4±0.02µs 0.00%
String Object Access (Compiler) 1411.0±3.25ns 1439.8±4.97ns +2.04%
String Object Access (Execution) 6.0±0.02µs 5.8±0.02µs -3.33%
String Object Access (Parser) 14.9±0.01µs 14.7±0.03µs -1.34%
String comparison (Compiler) 2.1±0.00µs 2.1±0.00µs 0.00%
String comparison (Execution) 4.6±0.02µs 4.5±0.01µs -2.17%
String comparison (Parser) 11.6±0.01µs 11.6±0.02µs 0.00%
String concatenation (Compiler) 1615.5±3.49ns 1653.9±2.96ns +2.38%
String concatenation (Execution) 4.4±0.01µs 4.3±0.01µs -2.27%
String concatenation (Parser) 8.0±0.02µs 8.0±0.02µs 0.00%
String copy (Compiler) 1296.3±10.44ns 1292.9±3.57ns -0.26%
String copy (Execution) 4.1±0.02µs 4.0±0.01µs -2.44%
String copy (Parser) 6.0±0.02µs 6.0±0.01µs 0.00%
Symbols (Compiler) 927.7±3.77ns 926.6±3.57ns -0.12%
Symbols (Execution) 4.2±0.01µs 4.2±0.01µs 0.00%
Symbols (Parser) 4.6±0.01µs 4.5±0.01µs -2.17%

@HalidOdat HalidOdat force-pushed the feature/jsfunction branch from 1396564 to 2e236a1 Compare April 16, 2022 22:23
@github-actions
Copy link

Benchmark for 3b74e5d

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 616.1±7.79ns 598.3±20.05ns -2.89%
Arithmetic operations (Execution) 740.6±11.68ns 747.6±22.13ns +0.95%
Arithmetic operations (Parser) 6.2±0.20µs 6.1±0.21µs -1.61%
Array access (Compiler) 1489.2±49.92ns 1551.7±59.02ns +4.20%
Array access (Execution) 8.9±0.17µs 9.5±0.34µs +6.74%
Array access (Parser) 13.6±0.31µs 13.0±0.48µs -4.41%
Array creation (Compiler) 2.2±0.06µs 2.2±0.08µs 0.00%
Array creation (Execution) 3.0±0.05ms 3.0±0.10ms 0.00%
Array creation (Parser) 15.5±0.40µs 15.1±0.49µs -2.58%
Array pop (Compiler) 4.4±0.06µs 4.2±0.13µs -4.55%
Array pop (Execution) 1324.2±16.75µs 1305.6±44.09µs -1.40%
Array pop (Parser) 160.2±3.95µs 155.2±5.62µs -3.12%
Boolean Object Access (Compiler) 1130.8±25.67ns 1062.0±74.13ns -6.08%
Boolean Object Access (Execution) 4.8±0.09µs 5.2±0.20µs +8.33%
Boolean Object Access (Parser) 16.4±0.54µs 16.0±0.56µs -2.44%
Clean js (Compiler) 3.8±0.05µs 3.9±0.14µs +2.63%
Clean js (Execution) 799.4±16.62µs 844.8±33.02µs +5.68%
Clean js (Parser) 33.3±0.92µs 32.3±0.94µs -3.00%
Create Realm 324.0±7.49ns 322.7±12.18ns -0.40%
Dynamic Object Property Access (Compiler) 1891.0±56.60ns 2.0±0.06µs +5.76%
Dynamic Object Property Access (Execution) 6.1±0.14µs 6.7±0.20µs +9.84%
Dynamic Object Property Access (Parser) 12.1±0.22µs 11.4±0.39µs -5.79%
Fibonacci (Compiler) 2.6±0.07µs 2.8±0.05µs +7.69%
Fibonacci (Execution) 1558.1±39.56µs 1556.7±46.77µs -0.09%
Fibonacci (Parser) 19.0±0.23µs 17.8±0.62µs -6.32%
For loop (Compiler) 2.3±0.07µs 2.4±0.06µs +4.35%
For loop (Execution) 17.5±0.44µs 17.7±0.53µs +1.14%
For loop (Parser) 16.1±0.23µs 15.5±0.51µs -3.73%
Mini js (Compiler) 3.7±0.09µs 3.7±0.13µs 0.00%
Mini js (Execution) 760.0±14.10µs 819.0±16.73µs +7.76%
Mini js (Parser) 29.2±0.86µs 28.3±1.04µs -3.08%
Number Object Access (Compiler) 1106.3±21.55ns 1040.7±38.91ns -5.93%
Number Object Access (Execution) 3.7±0.06µs 4.1±0.13µs +10.81%
Number Object Access (Parser) 12.7±0.34µs 12.1±0.44µs -4.72%
Object Creation (Compiler) 1617.0±44.07ns 1790.3±27.56ns +10.72%
Object Creation (Execution) 5.7±0.17µs 6.2±0.23µs +8.77%
Object Creation (Parser) 10.5±0.15µs 10.0±0.41µs -4.76%
RegExp (Compiler) 1987.6±38.01ns 2.0±0.07µs +0.62%
RegExp (Execution) 12.6±0.28µs 13.7±0.47µs +8.73%
RegExp (Parser) 11.5±0.23µs 11.2±0.42µs -2.61%
RegExp Creation (Compiler) 1709.3±27.28ns 1719.9±57.47ns +0.62%
RegExp Creation (Execution) 9.6±0.20µs 10.5±0.21µs +9.38%
RegExp Creation (Parser) 9.6±0.20µs 9.1±0.38µs -5.21%
RegExp Literal (Compiler) 1963.1±25.49ns 2.0±0.07µs +1.88%
RegExp Literal (Execution) 12.8±0.26µs 13.5±0.42µs +5.47%
RegExp Literal (Parser) 9.3±0.21µs 9.0±0.35µs -3.23%
RegExp Literal Creation (Compiler) 1708.4±25.82ns 1735.6±50.55ns +1.59%
RegExp Literal Creation (Execution) 9.5±0.25µs 10.5±0.32µs +10.53%
RegExp Literal Creation (Parser) 7.2±0.18µs 7.1±0.25µs -1.39%
Static Object Property Access (Compiler) 1626.5±39.09ns 1767.2±40.66ns +8.65%
Static Object Property Access (Execution) 5.9±0.18µs 6.3±0.25µs +6.78%
Static Object Property Access (Parser) 11.3±0.14µs 10.7±0.41µs -5.31%
String Object Access (Compiler) 1610.1±39.69ns 1541.1±49.79ns -4.29%
String Object Access (Execution) 6.8±0.12µs 7.5±0.27µs +10.29%
String Object Access (Parser) 16.2±0.39µs 15.9±0.49µs -1.85%
String comparison (Compiler) 2.4±0.05µs 2.7±0.06µs +12.50%
String comparison (Execution) 5.3±0.08µs 5.5±0.17µs +3.77%
String comparison (Parser) 12.7±0.31µs 12.2±0.45µs -3.94%
String concatenation (Compiler) 1917.2±26.07ns 2.0±0.07µs +4.32%
String concatenation (Execution) 5.1±0.08µs 5.3±0.17µs +3.92%
String concatenation (Parser) 8.6±0.18µs 8.3±0.27µs -3.49%
String copy (Compiler) 1482.2±47.86ns 1654.4±53.04ns +11.62%
String copy (Execution) 4.7±0.11µs 5.0±0.16µs +6.38%
String copy (Parser) 6.4±0.13µs 6.2±0.21µs -3.13%
Symbols (Compiler) 1083.1±29.80ns 1157.1±18.55ns +6.83%
Symbols (Execution) 4.7±0.20µs 5.1±0.15µs +8.51%
Symbols (Parser) 4.9±0.10µs 4.7±0.17µs -4.08%

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, but I'm missing some documentation on public methods (of JsFunction and other public APIs) in order to make this very usable, maybe with some example code, for instance.

boa_engine/src/object/jsfunction.rs Show resolved Hide resolved
@HalidOdat HalidOdat force-pushed the feature/jsfunction branch from 2e236a1 to 452a91f Compare April 24, 2022 15:27
@HalidOdat HalidOdat force-pushed the feature/jsfunction branch from 452a91f to 257097b Compare April 24, 2022 15:34
@github-actions
Copy link

Benchmark for 3af59f7

Click to view benchmark
Test Base PR %
Arithmetic operations (Compiler) 619.8±10.82ns 588.6±14.28ns -5.03%
Arithmetic operations (Execution) 692.2±12.56ns 714.9±13.17ns +3.28%
Arithmetic operations (Parser) 6.1±0.16µs 6.1±0.13µs 0.00%
Array access (Compiler) 1463.1±41.93ns 1473.2±28.61ns +0.69%
Array access (Execution) 8.7±0.17µs 8.8±0.17µs +1.15%
Array access (Parser) 13.4±0.29µs 13.3±0.32µs -0.75%
Array creation (Compiler) 2.1±0.05µs 2.1±0.07µs 0.00%
Array creation (Execution) 2.9±0.06ms 2.9±0.06ms 0.00%
Array creation (Parser) 15.0±0.30µs 15.1±0.36µs +0.67%
Array pop (Compiler) 4.2±0.09µs 4.6±0.10µs +9.52%
Array pop (Execution) 1291.9±37.29µs 1264.8±31.46µs -2.10%
Array pop (Parser) 155.3±3.66µs 156.1±3.24µs +0.52%
Boolean Object Access (Compiler) 1063.8±25.02ns 1080.0±20.72ns +1.52%
Boolean Object Access (Execution) 4.6±0.11µs 4.8±0.14µs +4.35%
Boolean Object Access (Parser) 15.8±0.42µs 16.1±0.39µs +1.90%
Clean js (Compiler) 3.8±0.13µs 3.8±0.07µs 0.00%
Clean js (Execution) 789.2±17.88µs 768.5±12.02µs -2.62%
Clean js (Parser) 32.8±0.83µs 33.0±0.75µs +0.61%
Create Realm 315.6±7.56ns 322.8±5.92ns +2.28%
Dynamic Object Property Access (Compiler) 1876.2±34.26ns 1856.6±39.77ns -1.04%
Dynamic Object Property Access (Execution) 6.4±0.09µs 6.0±0.12µs -6.25%
Dynamic Object Property Access (Parser) 11.9±0.21µs 11.6±0.25µs -2.52%
Fibonacci (Compiler) 2.6±0.06µs 2.6±0.06µs 0.00%
Fibonacci (Execution) 1476.3±37.66µs 1475.4±24.20µs -0.06%
Fibonacci (Parser) 18.1±0.36µs 17.9±0.44µs -1.10%
For loop (Compiler) 2.3±0.05µs 2.3±0.05µs 0.00%
For loop (Execution) 17.2±0.39µs 17.2±0.51µs 0.00%
For loop (Parser) 15.5±0.31µs 15.9±0.44µs +2.58%
Mini js (Compiler) 3.7±0.08µs 3.7±0.07µs 0.00%
Mini js (Execution) 757.4±17.20µs 734.8±13.68µs -2.98%
Mini js (Parser) 28.6±0.49µs 28.7±0.57µs +0.35%
Number Object Access (Compiler) 1048.5±18.70ns 1054.3±22.62ns +0.55%
Number Object Access (Execution) 3.6±0.07µs 3.6±0.09µs 0.00%
Number Object Access (Parser) 12.3±0.30µs 12.3±0.25µs 0.00%
Object Creation (Compiler) 1618.1±29.61ns 1564.5±29.81ns -3.31%
Object Creation (Execution) 5.8±0.17µs 5.7±0.14µs -1.72%
Object Creation (Parser) 10.0±0.25µs 10.1±0.25µs +1.00%
RegExp (Compiler) 1904.8±42.42ns 1854.2±34.47ns -2.66%
RegExp (Execution) 12.6±0.28µs 12.4±0.30µs -1.59%
RegExp (Parser) 11.2±0.26µs 11.3±0.31µs +0.89%
RegExp Creation (Compiler) 1658.0±43.88ns 1601.8±35.82ns -3.39%
RegExp Creation (Execution) 9.3±0.20µs 9.4±0.22µs +1.08%
RegExp Creation (Parser) 9.5±0.16µs 9.3±0.17µs -2.11%
RegExp Literal (Compiler) 1888.4±47.67ns 1846.9±50.02ns -2.20%
RegExp Literal (Execution) 12.6±0.32µs 12.6±0.26µs 0.00%
RegExp Literal (Parser) 9.2±0.15µs 9.1±0.15µs -1.09%
RegExp Literal Creation (Compiler) 1658.2±37.62ns 1671.6±35.54ns +0.81%
RegExp Literal Creation (Execution) 9.5±0.22µs 9.3±0.22µs -2.11%
RegExp Literal Creation (Parser) 7.2±0.15µs 7.1±0.16µs -1.39%
Static Object Property Access (Compiler) 1652.9±27.82ns 1612.6±32.52ns -2.44%
Static Object Property Access (Execution) 6.0±0.13µs 5.8±0.15µs -3.33%
Static Object Property Access (Parser) 10.9±0.22µs 11.1±0.25µs +1.83%
String Object Access (Compiler) 1495.5±32.54ns 1494.2±38.38ns -0.09%
String Object Access (Execution) 6.7±0.12µs 6.7±0.12µs 0.00%
String Object Access (Parser) 15.6±0.31µs 15.8±0.35µs +1.28%
String comparison (Compiler) 2.4±0.06µs 2.4±0.05µs 0.00%
String comparison (Execution) 5.1±0.11µs 5.1±0.11µs 0.00%
String comparison (Parser) 12.5±0.29µs 12.3±0.22µs -1.60%
String concatenation (Compiler) 1872.5±44.20ns 1898.1±39.98ns +1.37%
String concatenation (Execution) 5.0±0.11µs 4.9±0.10µs -2.00%
String concatenation (Parser) 8.3±0.18µs 8.5±0.23µs +2.41%
String copy (Compiler) 1512.4±36.83ns 1483.6±25.87ns -1.90%
String copy (Execution) 4.7±0.09µs 4.6±0.12µs -2.13%
String copy (Parser) 6.3±0.13µs 6.2±0.13µs -1.59%
Symbols (Compiler) 1083.2±25.22ns 1062.4±19.26ns -1.92%
Symbols (Execution) 4.7±0.11µs 4.8±0.10µs +2.13%
Symbols (Parser) 4.7±0.10µs 4.7±0.15µs 0.00%

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.

This is good for me :) Let's see what the rest thinks.

@raskad
Copy link
Member

raskad commented May 1, 2022

bors r+

bors bot pushed a commit that referenced this pull request May 1, 2022
This PR adds `JsFunction` wrapper around JavaScript `Function` object, like #1746 
With this PR we can distinguish between regular object and function object when we need, such as accessors (because they always need to be functions), predicates in `JsArray` methods like `map`, `find`, etc. With this abstraction we leverage the type system of rust which cleans the API making intentions clear.

It changes the following:
- Make methods that take predicate/callback function take `JsFunction`s
- Make `.accessor()` and `.static_accessor()` take `Option<JsFunction>`
- Make `FunctionBuilder` return `JsFunction`
- Make `ConstructorBuilder` return `JsFunction`
- Make `ClassBuilder` return `JsFunction`
@bors
Copy link

bors bot commented May 1, 2022

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title Feature JsFunction [Merged by Bors] - Feature JsFunction May 1, 2022
@bors bors bot closed this May 1, 2022
@bors bors bot deleted the feature/jsfunction branch May 1, 2022 17:15
Razican pushed a commit that referenced this pull request Jun 8, 2022
This PR adds `JsFunction` wrapper around JavaScript `Function` object, like #1746 
With this PR we can distinguish between regular object and function object when we need, such as accessors (because they always need to be functions), predicates in `JsArray` methods like `map`, `find`, etc. With this abstraction we leverage the type system of rust which cleans the API making intentions clear.

It changes the following:
- Make methods that take predicate/callback function take `JsFunction`s
- Make `.accessor()` and `.static_accessor()` take `Option<JsFunction>`
- Make `FunctionBuilder` return `JsFunction`
- Make `ConstructorBuilder` return `JsFunction`
- Make `ClassBuilder` return `JsFunction`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants