Skip to content

Refactor old function with new function object - #255

Merged
jasonwilliams merged 1 commit into
masterfrom
function_objs
May 3, 2020
Merged

jasonwilliams merged 1 commit into
masterfrom
function_objs

Conversation

@jasonwilliams

@jasonwilliams jasonwilliams commented Feb 20, 2020 •

Copy link
Copy Markdown
Member

Fixes #141

  • Implement fmt::Display for new function
  • Fix isFunction()
  • Better documentation for functions
  • Fall back to construct if call is not defined
  • all functions point to Function.prototype internally
  • leaner make_constructer_fn!()
  • deprecation of set_internal_method()
  • deprecation of set_method()
  • construct / call duplication
  • typeof is both a Node and a method in Value

@jasonwilliams jasonwilliams changed the title function objects fixes #141 [WIP] - function objects fixes #141 Feb 20, 2020
@github-actions

Copy link
Copy Markdown

Benchmark for bb3f46c

Click to view benchmark
Test PR Benchmark Master Benchmark %
Create Realm 452.9±10.90µs 439.6±14.21µs 103%
Expression (Parser) 10.9±0.66µs 10.9±0.16µs 100%
Hello World (Execution) 457.2±11.42µs 460.3±14.52µs 99%
Hello World (Lexer) 1127.1±43.92ns 1156.0±184.93ns 97%
Hello World (Parser) 1393.4±28.05ns 1401.8±25.08ns 99%
Symbol Creation 529.1±12.09µs 514.6±27.02µs 103%
fibonacci (Execution) 5.2±0.11ms 5.0±0.07ms 105%
undefined undefined 100%

@github-actions

github-actions Bot commented Mar 9, 2020

Copy link
Copy Markdown

Benchmark for 6f94faf

Click to view benchmark
Test PR Benchmark Master Benchmark %
Create Realm 395.2±17.92µs 380.8±17.74µs 104%
Expression (Parser) 9.7±0.35µs 9.4±0.55µs 103%
Hello World (Execution) 407.5±16.00µs 389.3±16.18µs 105%
Hello World (Lexer) 926.9±38.59ns 926.0±50.04ns 100%
Hello World (Parser) 1231.9±41.61ns 1216.7±65.25ns 101%
Symbol Creation 466.3±17.29µs 450.6±24.43µs 103%
fibonacci (Execution) 4.5±0.09ms 4.4±0.27ms 103%
undefined undefined 100%

@Razican Razican added the A-Enhancement New feature or request label Apr 14, 2020
@Razican

Razican commented Apr 14, 2020

Copy link
Copy Markdown
Member

I think this would be a nice addition to Boa 0.8, and it could potentially solve #266. What extra work is needed here?

@jasonwilliams

Copy link
Copy Markdown
Member Author

I’ll dig this up again, I remember being blocked on something, leave it with me for now

@jasonwilliams

Copy link
Copy Markdown
Member Author

Most of the properties are there, now its a case of replacing the old function with this one

@github-actions

Copy link
Copy Markdown

Benchmark for 4c03ffa

Click to view benchmark
Test PR Benchmark Master Benchmark %
Create Realm 340.8±12.32µs 334.9±7.70µs 102%
Expression (Lexer) 2.0±0.09µs 2.0±0.05µs 99%
Expression (Parser) 4.8±0.17µs 4.8±0.13µs 101%
Fibonacci (Execution) 3.6±0.11ms 3.5±0.05ms 104%
For loop (Execution) 351.2±23.48µs 343.8±6.02µs 102%
For loop (Lexer) 5.0±0.59µs 5.1±0.12µs 99%
For loop (Parser) 12.1±0.27µs 12.2±0.58µs 99%
Hello World (Lexer) 872.7±22.72ns 875.5±17.33ns 100%
Hello World (Parser) 1977.2±43.19ns 1982.1±57.34ns 100%
Symbols (Execution) 365.8±14.21µs 353.5±6.45µs 103%
undefined undefined 100%

@jasonwilliams

jasonwilliams commented Apr 20, 2020 •

Copy link
Copy Markdown
Member Author

Almost there, i hit a pretty weird error.
Seems to be to do with printing the new function object.

Would appreciate another pair of eyes

function hello() {
  console.log("hello");
}

const a = hello();
a;
undefinedthread '<unnamed>' panicked at 'assertion failed: finalizer_safe()', <::std::macros::panic macros>:2:4
stack backtrace:
   0: std::sys_common::backtrace::_print::{{impl}}::fmt
   at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\sys_common\backtrace.rs:59
   1: core::fmt::write
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libcore\fmt\mod.rs:1052
   2: std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\io\mod.rs:1426
   3: std::panicking::default_hook::{{closure}}
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:204
   4: std::panicking::default_hook
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:224
   5: std::panicking::rust_panic_with_hook
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:472
   6: std::panicking::begin_panic<str*>
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\src\libstd\panicking.rs:399 
   7: gc::Gc<boa::builtins::value::ValueData>::inner<boa::builtins::value::ValueData>       
             at <::std::macros::panic macros>:2
   8: gc::{{impl}}::drop<boa::builtins::value::ValueData>
             at C:\Users\jasew\.cargo\registry\src\github.com-1ecc6299db9ec823\gc-0.3.3\src\lib.rs:263
   9: hashbrown::raw::{{impl}}::drop<(alloc::string::String, gc::Gc<boa::builtins::value::ValueData>)>
             at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\hashbrown-0.6.2\src\raw\mod.rs:1041
  10: core::ptr::drop_in_place<alloc::boxed::Box<std::collections::hash::map::HashMap<alloc::string::String, gc::Gc<boa::builtins::value::ValueData>, std::collections::hash::map::RandomState>>>
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\src\libcore\ptr\mod.rs:174
  11: core::ptr::drop_in_place<boa::builtins::function_object::Function>
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\src\libcore\ptr\mod.rs:174
  12: core::ptr::drop_in_place<alloc::boxed::Box<gc::gc::GcBox<Trace>>>
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\src\libcore\ptr\mod.rs:174
  13: gc::gc::{{impl}}::drop
             at C:\Users\jasew\.cargo\registry\src\github.com-1ecc6299db9ec823\gc-0.3.3\src\gc.rs:36
  14: std::thread::local::fast::destroy_value<core::cell::RefCell<gc::gc::GcState>>
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\src\libstd\thread\local.rs:459
  15: std::sys_common::thread_local::register_dtor_fallback::run_dtors
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\sys_common\thread_local.rs:260
  16: std::sys::windows::thread_local::on_tls_callback
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\sys\windows\thread_local.rs:198
  17: RtlActivateActivationContextUnsafeFast
  18: RtlActivateActivationContextUnsafeFast
  19: LdrShutdownProcess
  20: RtlExitUserProcess
  21: ExitProcess
  22: o_free
  23: exit
  24: __scrt_common_main_seh
             at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:295
  25: BaseThreadInitThunk
  26: RtlUserThreadStart
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread '<unnamed>' panicked at 'assertion failed: finalizer_safe()', <::std::macros::panic macros>:2:4
stack backtrace:
   0:     0x7ff78c2d46f9 - std::sys_common::backtrace::_print::{{impl}}::fmt
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\sys_common\backtrace.rs:59
   1:     0x7ff78c2e376b - core::fmt::write
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libcore\fmt\mod.rs:1052
   2:     0x7ff78c2d1ed4 - std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\io\mod.rs:1426
   3:     0x7ff78c2d719c - std::panicking::default_hook::{{closure}}
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:204
   4:     0x7ff78c2d6dec - std::panicking::default_hook
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:224
   5:     0x7ff78c2d78ef - std::panicking::rust_panic_with_hook
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:472
   6:     0x7ff78c2c6f36 - std::panicking::begin_panic<str*>
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\src\libstd\panicking.rs:399
   7:     0x7ff78c34f078 - gc::Gc<gc::GcCell<alloc::boxed::Box<EnvironmentRecordTrait>>>::inner<gc::GcCell<alloc::boxed::Box<EnvironmentRecordTrait>>>
                               at <::std::macros::panic macros>:2
   8:     0x7ff78c350f79 - gc::{{impl}}::drop<boa::builtins::value::ValueData>
                               at C:\Users\jasew\.cargo\registry\src\github.com-1ecc6299db9ec823\gc-0.3.3\src\lib.rs:263
   9:     0x7ff78c34fe1b - core::ptr::drop_in_place<boa::builtins::function_object::Function>
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\src\libcore\ptr\mod.rs:174
  10:     0x7ffe416b1030 - <unknown>
  11:     0x7ffe416b35d6 - is_exception_typeof
  12:     0x7ffe416bbb64 - _C_specific_handler
  13:     0x7ffe416b3029 - is_exception_typeof
  14:     0x7ffe416bc021 - _CxxFrameHandler3
  15:     0x7ffe5ff2124f - _chkstk
  16:     0x7ffe5fe9d9b2 - RtlUnwindEx
  17:     0x7ffe5ff0c699 - _C_specific_handler
  18:     0x7ffe5ff211cf - _chkstk
  19:     0x7ffe5feea209 - RtlRaiseException
  20:     0x7ffe5fee9fc3 - RtlRaiseException
  21:     0x7ffe5db3a799 - RaiseException
  22:     0x7ffe416b4890 - CxxThrowException
  23:     0x7ff78c394631 - panic_unwind::imp::panic
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libpanic_unwind\seh.rs:315
  24:     0x7ff78c3945b9 - panic_unwind::__rust_start_panic
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libpanic_unwind\lib.rs:111
  25:     0x7ff78c2d79b8 - std::panicking::rust_panic
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:524
  26:     0x7ff78c2d799d - std::panicking::rust_panic_with_hook
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\panicking.rs:494
  27:     0x7ff78c2c6f36 - std::panicking::begin_panic<str*>
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\src\libstd\panicking.rs:399
  28:     0x7ff78c30a058 - gc::Gc<boa::builtins::value::ValueData>::inner<boa::builtins::value::ValueData>
                               at <::std::macros::panic macros>:2
  29:     0x7ff78c30aa29 - gc::{{impl}}::drop<boa::builtins::value::ValueData>
                               at C:\Users\jasew\.cargo\registry\src\github.com-1ecc6299db9ec823\gc-0.3.3\src\lib.rs:263
  30:     0x7ff78c30b40d - hashbrown::raw::{{impl}}::drop<(alloc::string::String, gc::Gc<boa::builtins::value::ValueData>)>
                               at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\hashbrown-0.6.2\src\raw\mod.rs:1041
  31:     0x7ff78c3502fe - core::ptr::drop_in_place<alloc::boxed::Box<std::collections::hash::map::HashMap<alloc::string::String, gc::Gc<boa::builtins::value::ValueData>, std::collections::hash::map::RandomState>>>
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\src\libcore\ptr\mod.rs:174
  32:     0x7ff78c34fdab - core::ptr::drop_in_place<boa::builtins::function_object::Function>
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\src\libcore\ptr\mod.rs:174
  33:     0x7ff78c2c7715 - core::ptr::drop_in_place<alloc::boxed::Box<gc::gc::GcBox<Trace>>>
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\src\libcore\ptr\mod.rs:174
  34:     0x7ff78c2c790d - gc::gc::{{impl}}::drop
                               at C:\Users\jasew\.cargo\registry\src\github.com-1ecc6299db9ec823\gc-0.3.3\src\gc.rs:36
  35:     0x7ff78c392bbe - std::thread::local::fast::destroy_value<core::cell::RefCell<gc::gc::GcState>>
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\src\libstd\thread\local.rs:459
  36:     0x7ff78c2d5cae - std::sys_common::thread_local::register_dtor_fallback::run_dtors
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\sys_common\thread_local.rs:260
  37:     0x7ff78c2d95a8 - std::sys::windows::thread_local::on_tls_callback
                               at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\/src\libstd\sys\windows\thread_local.rs:198
  38:     0x7ffe5fea5021 - RtlActivateActivationContextUnsafeFast
  39:     0x7ffe5fea5103 - RtlActivateActivationContextUnsafeFast
  40:     0x7ffe5feeab30 - LdrShutdownProcess
  41:     0x7ffe5feea92d - RtlExitUserProcess
  42:     0x7ffe5ef6cd8a - ExitProcess
  43:     0x7ffe5de4ae38 - o_free
  44:     0x7ffe5de486ef - exit
  45:     0x7ff78c41ae87 - __scrt_common_main_seh
                               at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:295
  46:     0x7ffe5ef67bd4 - BaseThreadInitThunk
  47:     0x7ffe5feece51 - RtlUserThreadStart
thread panicked while panicking. aborting.
```

@HalidOdat

Copy link
Copy Markdown
Member

I will take a look, to see whats causing this. :)

@HalidOdat

HalidOdat commented Apr 20, 2020 •

Copy link
Copy Markdown
Member

Well...
I found were the bug originates but not what causes it.

Its in an unsafe block in lib.rs line: 263 (in gc crate)
It seems to be related to garbage collection when dropping garbage collected values.

I don't know much about the gc crate.

Hope that helps. :)

@HalidOdat

Copy link
Copy Markdown
Member
function hello() {
  console.log("hello");
}

const a = hello();
a;

The above code runs and returns undefined and then panics.

								    The panic.
										|
		 ____________________________________________________________________
		 \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
undefinedthread '<unnamed>' panicked at 'assertion failed: finalizer_safe()', 
^^^^^^^^^
   |
The returned value.

@jasonwilliams

Copy link
Copy Markdown
Member Author

Hey thanks @HalidOdat
hmmm yeah i noticed that too!

Ill take a look and see what im doing with Gc

@jasonwilliams

Copy link
Copy Markdown
Member Author

Sorted it

Tests remaining

    builtins::array::tests::every
    builtins::array::tests::find_index
    builtins::array::tests::for_each
    builtins::array::tests::for_each_push_value
    builtins::array::tests::some
    builtins::symbol::tests::check_symbol_constructor_is_function
    exec::tests::test_short_circuit_evaluation

@jasonwilliams jasonwilliams changed the title [WIP] - function objects fixes #141 [WIP] - Refactor old function with new function object fixes #141 Apr 20, 2020
@HalidOdat

HalidOdat commented Apr 20, 2020 •

Copy link
Copy Markdown
Member

Why do we have function and function_object?

@jasonwilliams

Copy link
Copy Markdown
Member Author

Why do we have function and function_object?

function will be replaced and function_object will be called function, i just need them both right now while i transition in this PR.

once all tests pass and im happy with it ill get rid of all the old function code

@jasonwilliams

jasonwilliams commented Apr 25, 2020 •

Copy link
Copy Markdown
Member Author

Ugh I’m going to have to refactor this, I forgot a single function can be both a call and construct call. So in the function struct I think Instead of body I’ll need call_body and construct_body

@Razican
Razican marked this pull request as draft April 25, 2020 19:27
@Razican Razican changed the title [WIP] - Refactor old function with new function object fixes #141 Refactor old function with new function object fixes #141 Apr 25, 2020
@jasonwilliams

jasonwilliams commented Apr 26, 2020 •

Copy link
Copy Markdown
Member Author

I'm leaning towards the idea of Object having a call: Option<Function> and a construct: Option<Function> added on to them, and Function can remove all the overlap with objects (internal_slots, properties).

@github-actions

github-actions Bot commented May 1, 2020

Copy link
Copy Markdown

Benchmark for b027db7

Click to view benchmark
Test PR Benchmark Master Benchmark %
Create Realm 539.6±11.83µs 360.4±11.35µs 150%
Expression (Lexer) 2.1±0.05µs 1884.1±56.94ns 112.99999999999999%
Expression (Parser) 4.9±0.14µs 4.8±0.13µs 102%
Fibonacci (Execution) 4.4±0.11ms 3.5±0.06ms 125%
For loop (Execution) 573.2±9.05µs 380.7±10.70µs 151%
For loop (Lexer) 5.9±0.14µs 5.2±0.18µs 113.99999999999999%
For loop (Parser) 13.9±0.29µs 14.0±0.36µs 99%
Hello World (Lexer) 983.7±15.01ns 922.9±20.28ns 107%
Hello World (Parser) 2.3±0.06µs 2.2±0.06µs 104%
Symbols (Execution) 582.5±10.05µs 400.8±11.90µs 145%
undefined undefined 100%

@github-actions

github-actions Bot commented May 1, 2020

Copy link
Copy Markdown

Benchmark for 64452b3

Click to view benchmark
Test PR Benchmark Master Benchmark %
Create Realm 597.9±22.02µs 385.6±18.60µs 155%
Expression (Lexer) 1992.4±90.36ns 1904.3±136.32ns 105%
Expression (Parser) 5.1±0.23µs 4.9±0.42µs 104%
Fibonacci (Execution) 5.0±0.18ms 3.9±0.13ms 130%
For loop (Execution) 607.1±27.90µs 392.6±21.25µs 155%
For loop (Lexer) 5.1±0.25µs 5.2±0.30µs 99%
For loop (Parser) 14.6±0.84µs 14.7±0.89µs 99%
Hello World (Lexer) 945.1±60.49ns 913.6±44.02ns 103%
Hello World (Parser) 2.4±0.08µs 2.2±0.15µs 108%
Symbols (Execution) 625.0±24.30µs 403.2±12.55µs 155%
undefined undefined 100%

@github-actions

github-actions Bot commented May 1, 2020

Copy link
Copy Markdown

Benchmark for 19ff051

Click to view benchmark
Test PR Benchmark Master Benchmark %
Create Realm 604.4±41.03µs 366.9±16.87µs 165%
Expression (Lexer) 1939.0±99.51ns 1935.9±142.23ns 100%
Expression (Parser) 5.1±0.32µs 4.9±0.27µs 105%
Fibonacci (Execution) 5.1±0.17ms 3.9±0.19ms 131%
For loop (Execution) 623.9±37.91µs 396.2±22.95µs 157%
For loop (Lexer) 5.1±0.30µs 5.2±0.40µs 100%
For loop (Parser) 14.3±0.75µs 14.5±0.81µs 99%
Hello World (Lexer) 912.1±35.81ns 922.7±52.17ns 99%
Hello World (Parser) 2.4±0.15µs 2.3±0.10µs 104%
Symbols (Execution) 646.4±35.40µs 398.6±15.89µs 162%
undefined undefined 100%

@github-actions

github-actions Bot commented May 1, 2020

Copy link
Copy Markdown

Benchmark for c13aef3

Click to view benchmark
Test PR Benchmark Master Benchmark %
Create Realm 566.5±22.14µs 355.3±20.88µs 159%
Expression (Lexer) 2.1±0.11µs 1876.2±123.19ns 113.99999999999999%
Expression (Parser) 4.8±0.38µs 4.6±0.22µs 103%
Fibonacci (Execution) 4.8±0.19ms 3.8±0.14ms 128%
For loop (Execution) 595.8±48.08µs 379.1±25.56µs 157%
For loop (Lexer) 5.8±0.41µs 4.8±0.25µs 121%
For loop (Parser) 13.8±0.87µs 13.8±0.64µs 100%
Hello World (Lexer) 924.6±44.16ns 880.3±46.10ns 105%
Hello World (Parser) 2.2±0.10µs 2.2±0.12µs 99%
Symbols (Execution) 597.4±28.87µs 377.7±19.43µs 158%
undefined undefined 100%

@jasonwilliams
jasonwilliams marked this pull request as ready for review May 1, 2020 22:25
@github-actions

github-actions Bot commented May 1, 2020

Copy link
Copy Markdown

Benchmark for 649cfb5

Click to view benchmark
Test PR Benchmark Master Benchmark %
Create Realm 519.1±26.87µs 365.4±15.98µs 142%
Expression (Lexer) 1916.6±145.06ns 1892.1±150.72ns 101%
Expression (Parser) 4.8±0.24µs 4.8±0.33µs 100%
Fibonacci (Execution) 4.2±0.17ms 3.4±0.15ms 122%
For loop (Execution) 547.5±36.18µs 378.4±26.76µs 145%
For loop (Lexer) 5.1±0.36µs 4.9±0.24µs 106%
For loop (Parser) 13.2±0.73µs 13.7±0.52µs 96%
Hello World (Lexer) 884.5±33.39ns 870.7±41.80ns 102%
Hello World (Parser) 2.1±0.13µs 2.2±0.08µs 97%
Symbols (Execution) 562.9±49.51µs 381.0±27.53µs 148%
undefined undefined 100%

@github-actions

github-actions Bot commented May 1, 2020

Copy link
Copy Markdown

Benchmark for b14ccee

Click to view benchmark
Test PR Benchmark Master Benchmark %
Create Realm 619.1±33.43µs 390.6±10.38µs 159%
Expression (Lexer) 2.1±0.09µs 2.0±0.08µs 103%
Expression (Parser) 5.4±0.19µs 5.3±0.26µs 102%
Fibonacci (Execution) 5.5±0.11ms 4.1±0.11ms 133%
For loop (Execution) 656.5±41.10µs 413.5±18.17µs 159%
For loop (Lexer) 5.3±0.24µs 5.6±0.28µs 95%
For loop (Parser) 15.7±1.08µs 15.5±0.53µs 101%
Hello World (Lexer) 960.8±37.10ns 1023.6±71.68ns 93%
Hello World (Parser) 2.5±0.13µs 2.5±0.09µs 102%
Symbols (Execution) 661.8±38.65µs 421.0±20.27µs 157%
undefined undefined 100%

@Razican

Razican commented May 2, 2020

Copy link
Copy Markdown
Member

Wow, great job!

It seems that execution time has gone up by more than 50%. I will try to see if there is any improvement to make in performance.

@Razican

Razican commented May 2, 2020

Copy link
Copy Markdown
Member

I did some profiling, and I noticed that our biggest pain point is with our heavy usage of HashMap and even the GC itself. #356 should help with this. I couldn't really find more pain points with profiling because this is hidding everything else.

I will re-check the code changes just in case.

/// [spec]: https://tc39.es/ecma262/#sec-math.sinh
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh
pub fn sinh(_: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn sinh(_: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just for my understanding, why do we need all these to be mutable?

@jasonwilliams jasonwilliams May 2, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The first argument this can be altered by Constructor functions.
Its up to them to change the this value however they want.

Example
Usually this starts out being a plain ordinary JS object, and new String() will add a [[StringData]] internal slot to it. This mutates the value.

Why this wasn't a compile error before i don't know, but something in my refactoring meant that rust now moans if you mutate it.
imo it should have always been an issue but we got away with it before.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For regular functions it doesn't need to be mutable, as the first argument is a reference to the function itself (wrapped in a Value).
I think in future we can have 2 separate signatures for Construct and Func, for now they use the same.

Comment thread boa/src/builtins/mod.rs Resolved

@Razican Razican left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I found some things that can be improved, give them a look :)

Comment thread boa/src/builtins/object/mod.rs Outdated

/// Defines the different types of objects.
#[derive(Trace, Finalize, Clone, Debug, Eq, PartialEq)]
#[derive(Trace, Finalize, Debug, Clone, Eq, PartialEq)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should probably implement Copy here. For that, we need to do an unsafe implementation of an empty Trace until Manishearth/rust-gc#87 gets resolved.

///
/// In our implementation, Function is extending Object by holding an object field which some extra data
/// Arrow functions don't define a `this` and thus are lexical, `function`s do define a this and thus are NonLexical
#[derive(Trace, Finalize, Debug, Clone)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should implement Copy here, by doing an unsafe implementation of an empty Trace, until Manishearth/rust-gc#87 gets solved.

Comment thread boa/src/builtins/function/mod.rs Resolved
Comment thread boa/src/builtins/function/mod.rs Resolved
Comment thread boa/src/builtins/function/mod.rs Resolved
Comment thread boa/src/builtins/object/mod.rs Resolved
Comment thread boa/src/builtins/object/mod.rs Resolved
Comment thread boa/src/builtins/string/tests.rs Resolved
Comment thread boa/src/builtins/value/mod.rs Resolved
@jasonwilliams

Copy link
Copy Markdown
Member Author

@Razican the function object is now in a box, the size_of Value has gone from 280 to 8

@Razican

Razican commented May 2, 2020

Copy link
Copy Markdown
Member

The error in the benchmarks is because I actually fixed the JavaScript code in the benchmark and now we reach https://github.com/jasonwilliams/boa/blob/master/boa/src/exec/mod.rs#L574 since for loops are not implemented. Maybe we should remove that benchmark until we actually have the for loop execution implemented.

Comment thread boa/src/builtins/function/mod.rs Resolved
@Razican Razican added this to the v0.8.0 milestone May 2, 2020
@github-actions

github-actions Bot commented May 2, 2020

Copy link
Copy Markdown

Benchmark for 794e565

Click to view benchmark
Test PR Benchmark Master Benchmark %
Create Realm 501.4±21.30µs 368.9±13.01µs 136%
Expression (Lexer) 1796.0±143.66ns 1841.4±86.94ns 97%
Expression (Parser) 4.8±0.14µs 4.9±0.25µs 98%
Fibonacci (Execution) 3.5±0.23ms 3.4±0.10ms 103%
For loop (Execution) 367.4±12.06µs undefined 100%
For loop (Lexer) 5.0±0.22µs 4.9±0.21µs 101%
For loop (Parser) 13.4±0.53µs 14.1±0.91µs 95%
Hello World (Lexer) 903.1±55.40ns 854.7±41.80ns 106%
Hello World (Parser) 2.2±0.13µs 2.2±0.06µs 101%
Symbols (Execution) 519.4±26.90µs 380.6±12.83µs 136%
undefined undefined 100%

@Razican Razican left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is good to go! :D

@HalidOdat

HalidOdat commented May 2, 2020 •

Copy link
Copy Markdown
Member

If it's possible could you wait. I would like to see what I can optimize, before merging :)

@github-actions

github-actions Bot commented May 3, 2020

Copy link
Copy Markdown

Benchmark for 7d4b663

Click to view benchmark
Test PR Benchmark Master Benchmark %
Create Realm 497.7±30.63µs 351.0±14.57µs 142%
Expression (Lexer) 1852.3±107.12ns 1831.0±146.97ns 101%
Expression (Parser) 4.7±0.20µs 4.8±0.23µs 97%
Fibonacci (Execution) 3.7±0.14ms 3.5±0.11ms 106%
For loop (Execution) 358.5±13.34µs undefined 100%
For loop (Lexer) 5.0±0.15µs 5.0±0.18µs 100%
For loop (Parser) 12.6±0.65µs 13.5±0.76µs 93%
Hello World (Lexer) 893.4±41.81ns 859.2±60.30ns 104%
Hello World (Parser) 2.1±0.15µs 2.2±0.11µs 96%
Symbols (Execution) 544.3±19.29µs 385.1±13.80µs 141%
undefined undefined 100%

@HalidOdat

Copy link
Copy Markdown
Member
  • Changed Interpreter::call to take a slice instead of Vec.
  • Removed some unnecessary cloning in Array and String object methods.
  • Fixed a bug were we didn't have length for ordinary and arrow functions.

@jasonwilliams
jasonwilliams merged commit f02babf into master May 3, 2020
@HalidOdat
HalidOdat deleted the function_objs branch May 3, 2020 17:42
@Razican Razican linked an issue May 23, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add call function for RegExp Implement Function Objects

3 participants