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

Feature native class objects (NativeObject and Class traits) #627

Merged
merged 7 commits into from Sep 1, 2020

Conversation

HalidOdat
Copy link
Member

@HalidOdat HalidOdat commented Aug 13, 2020

This is related to #445 and #446

It changes the following:

  • Added NativeObject trait
  • If an type implements Debug, Any + Trace it automatically is an NativeObject
  • It calls Trace trait so this is not unsound
  • Removed internal state
  • Added example
  • Added Class for native class creation. see example in boa/examples.

@HalidOdat HalidOdat added enhancement New feature or request deprecations Issues and PRs related to deprecations. execution Issues or PRs related to code execution labels Aug 13, 2020
@codecov
Copy link

codecov bot commented Aug 13, 2020

Codecov Report

Merging #627 into master will decrease coverage by 0.31%.
The diff coverage is 8.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #627      +/-   ##
==========================================
- Coverage   73.21%   72.90%   -0.32%     
==========================================
  Files         191      192       +1     
  Lines       13905    13988      +83     
==========================================
+ Hits        10181    10198      +17     
- Misses       3724     3790      +66     
Impacted Files Coverage Δ
boa/examples/classes.rs 0.00% <0.00%> (ø)
boa/src/builtins/object/internal_methods.rs 48.22% <ø> (+6.25%) ⬆️
boa/src/builtins/property/attribute/mod.rs 90.62% <ø> (ø)
boa/src/lib.rs 73.91% <ø> (ø)
boa/src/builtins/object/mod.rs 30.35% <1.29%> (-8.82%) ⬇️
boa/src/exec/mod.rs 67.83% <12.50%> (-2.90%) ⬇️
boa/src/builtins/json/mod.rs 81.57% <85.71%> (ø)
boa/src/builtins/function/mod.rs 79.77% <100.00%> (ø)
boa/src/builtins/property/mod.rs 50.34% <100.00%> (+0.34%) ⬆️
boa/src/builtins/math/tests.rs 100.00% <0.00%> (ø)
... and 3 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 cb93472...1cb6323. Read the comment docs.

@github-actions
Copy link

Benchmark for cb32a76

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 351.0±25.61ns 333.6±19.85ns +5.22%
Arithmetic operations (Full) 211.1±16.11µs 205.7±15.55µs +2.63%
Array access (Execution) 7.0±0.50µs 7.0±0.36µs 0.00%
Array access (Full) 234.0±23.36µs 225.5±16.73µs +3.77%
Array creation (Execution) 2.6±0.15ms 2.6±0.15ms 0.00%
Array creation (Full) 3.0±0.26ms 3.1±0.23ms -3.23%
Array pop (Execution) 905.4±40.91µs 942.3±73.75µs -3.92%
Array pop (Full) 1237.1±86.35µs 1228.0±54.14µs +0.74%
Boolean Object Access (Execution) 3.7±0.28µs 3.6±0.21µs +2.78%
Boolean Object Access (Full) 214.4±13.46µs 246.7±22.31µs -13.09%
Create Realm 370.9±25.58ns 411.3±36.93ns -9.82%
Dynamic Object Property Access (Execution) 4.5±0.37µs 4.4±0.28µs +2.27%
Dynamic Object Property Access (Full) 225.2±16.22µs 214.8±11.31µs +4.84%
Expression (Lexer) 2.1±0.14µs 1985.9±164.42ns +5.75%
Expression (Parser) 4.3±0.27µs 4.2±0.31µs +2.38%
Fibonacci (Execution) 792.4±50.64µs 818.5±51.41µs -3.19%
Fibonacci (Full) 1032.9±62.00µs 1024.9±55.55µs +0.78%
For loop (Execution) 19.0±1.85µs 20.4±1.62µs -6.86%
For loop (Full) 246.6±21.05µs 243.5±21.10µs +1.27%
For loop (Lexer) 4.3±0.31µs 4.5±0.39µs -4.44%
For loop (Parser) 11.4±0.76µs 12.1±1.00µs -5.79%
Goal Symbols (Parser) 7.0±0.49µs 6.9±0.43µs +1.45%
Hello World (Lexer) 669.3±31.87ns 696.5±48.91ns -3.91%
Hello World (Parser) 1716.2±116.86ns 1727.3±123.17ns -0.64%
Long file (Parser) 5.7±0.36ms 5.4±0.35ms +5.56%
Number Object Access (Execution) 3.0±0.28µs 2.9±0.24µs +3.45%
Number Object Access (Full) 214.8±13.11µs 222.2±20.34µs -3.33%
Object Creation (Execution) 3.8±0.29µs 3.8±0.18µs 0.00%
Object Creation (Full) 250.2±11.59µs 258.1±21.17µs -3.06%
RegExp (Execution) 56.1±2.75µs 60.5±5.89µs -7.27%
RegExp (Full) 345.5±24.51µs 337.8±23.31µs +2.28%
RegExp Literal (Execution) 60.7±3.53µs 65.2±6.40µs -6.90%
RegExp Literal (Full) 300.4±31.79µs 286.8±19.46µs +4.74%
RegExp Literal Creation (Execution) 60.7±5.49µs 57.3±3.08µs +5.93%
RegExp Literal Creation (Full) 354.9±33.81µs 346.8±23.34µs +2.34%
Static Object Property Access (Execution) 4.2±0.36µs 4.2±0.35µs 0.00%
Static Object Property Access (Full) 215.3±13.68µs 218.8±16.44µs -1.60%
String Object Access (Execution) 5.4±0.23µs 5.8±0.67µs -6.90%
String Object Access (Full) 215.7±9.21µs 220.0±16.92µs -1.95%
String comparison (Execution) 4.9±0.25µs 5.0±0.26µs -2.00%
String comparison (Full) 223.0±15.61µs 215.3±13.18µs +3.58%
String concatenation (Execution) 4.0±0.19µs 4.2±0.32µs -4.76%
String concatenation (Full) 224.0±19.29µs 209.8±12.21µs +6.77%
String copy (Execution) 3.0±0.15µs 3.1±0.20µs -3.23%
String copy (Full) 214.5±16.39µs 207.7±12.27µs +3.27%
Symbols (Execution) 2.5±0.21µs 2.6±0.21µs -3.85%
Symbols (Full) 200.4±15.54µs 199.6±17.68µs +0.40%

@Razican
Copy link
Member

Razican commented Aug 13, 2020

What do you think? @Razican

This looks great! But we need something to add methods to the object, constructors and so on. Maybe we could have some call() methods in the trait? they would receive a context and a method name, and then the trait implementor does its thing.

@HalidOdat HalidOdat added the API label Aug 13, 2020
@HalidOdat
Copy link
Member Author

HalidOdat commented Aug 13, 2020

What do you think? @Razican

This looks great! But we need something to add methods to the object, constructors and so on. Maybe we could have some call() methods in the trait? they would receive a context and a method name, and then the trait implementor does its thing.

Yep. right now it's very minimal! It would be nice to have the contexts setup first.

@HalidOdat HalidOdat mentioned this pull request Aug 14, 2020
@github-actions
Copy link

Benchmark for 0118483

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 359.5±14.43ns 367.5±12.79ns -2.18%
Arithmetic operations (Full) 237.6±9.75µs 235.2±9.98µs +1.02%
Array access (Execution) 6.9±0.67µs 7.9±0.31µs -12.66%
Array access (Full) 237.6±11.12µs 245.6±8.41µs -3.26%
Array creation (Execution) 2.9±0.28ms 3.1±0.10ms -6.45%
Array creation (Full) 3.6±0.14ms 3.5±0.11ms +2.86%
Array pop (Execution) 1025.0±109.60µs 1122.8±33.46µs -8.71%
Array pop (Full) 1540.1±120.37µs 1457.6±46.26µs +5.66%
Boolean Object Access (Execution) 4.2±0.23µs 4.0±0.11µs +5.00%
Boolean Object Access (Full) 243.8±23.24µs 239.4±11.88µs +1.84%
Create Realm 374.0±43.13ns 441.3±15.99ns -15.25%
Dynamic Object Property Access (Execution) 4.4±0.72µs 4.8±0.16µs -8.33%
Dynamic Object Property Access (Full) 238.1±17.59µs 239.6±8.34µs -0.63%
Expression (Lexer) 2.3±0.08µs 2.3±0.30µs 0.00%
Expression (Parser) 5.1±0.15µs 5.1±0.18µs 0.00%
Fibonacci (Execution) 825.8±64.01µs 834.4±44.21µs -1.03%
Fibonacci (Full) 1107.5±50.23µs 1104.1±39.66µs +0.31%
For loop (Execution) 17.2±1.94µs 21.3±0.90µs -19.25%
For loop (Full) 255.4±10.20µs 263.0±15.45µs -2.89%
For loop (Lexer) 5.0±0.13µs 4.9±0.22µs +2.04%
For loop (Parser) 13.0±0.78µs 13.4±0.44µs -2.99%
Goal Symbols (Parser) 7.9±0.37µs 8.1±0.35µs -2.47%
Hello World (Lexer) 802.4±34.77ns 782.7±31.37ns +2.52%
Hello World (Parser) 1978.3±73.16ns 2.0±0.10µs -1.09%
Long file (Parser) 6.0±0.22ms 5.9±0.27ms +1.69%
Number Object Access (Execution) 3.1±0.14µs 3.2±0.26µs -3.13%
Number Object Access (Full) 232.8±7.65µs 234.4±9.42µs -0.68%
Object Creation (Execution) 3.9±0.31µs 4.0±0.13µs -2.50%
Object Creation (Full) 288.7±11.48µs 286.5±9.14µs +0.77%
RegExp (Execution) 63.9±3.75µs 62.3±2.46µs +2.57%
RegExp (Full) 383.7±18.47µs 380.2±13.18µs +0.92%
RegExp Literal (Execution) 67.1±3.37µs 65.2±2.31µs +2.91%
RegExp Literal (Full) 321.7±18.84µs 309.6±8.07µs +3.91%
RegExp Literal Creation (Execution) 52.5±4.89µs 63.1±3.96µs -16.80%
RegExp Literal Creation (Full) 375.9±23.34µs 379.1±15.11µs -0.84%
Static Object Property Access (Execution) 4.3±0.39µs 4.2±0.12µs +2.38%
Static Object Property Access (Full) 232.2±9.38µs 244.6±8.66µs -5.07%
String Object Access (Execution) 6.3±0.44µs 6.1±0.22µs +3.28%
String Object Access (Full) 240.8±9.32µs 247.4±11.75µs -2.67%
String comparison (Execution) 5.7±0.16µs 5.7±0.16µs 0.00%
String comparison (Full) 244.7±27.91µs 245.8±7.97µs -0.45%
String concatenation (Execution) 4.5±0.15µs 4.5±0.18µs 0.00%
String concatenation (Full) 234.9±9.46µs 238.9±9.26µs -1.67%
String copy (Execution) 3.2±0.17µs 3.3±0.11µs -3.03%
String copy (Full) 232.8±11.01µs 237.8±12.93µs -2.10%
Symbols (Execution) 2.4±0.27µs 2.7±0.14µs -11.11%
Symbols (Full) 215.8±12.40µs 223.9±9.13µs -3.62%

@HalidOdat
Copy link
Member Author

HalidOdat commented Aug 15, 2020

But we need something to add methods to the object, constructors and so on. Maybe we could have some call() methods in the trait? they would receive a context and a method name, and then the trait implementor does its thing.

About this. This is more of a class than an object, so NativeObject trait would allow passing the object around. For the constructor and methods we need another trait I called it Class with the following fields:

pub trait Class: NativeObject {
	const NAME: &'static str; // This is the binging name of the class
	const LENGTH: usize = 0; // Class `length` (the amount of arguments it takes) default is 0

	/// The constructor of the class
	fn constructor(this: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue;
	/// Initialize class methods
	fn methods(class: &mut ClassBuilder<'a>) -> ResultValue;
}

Now with 0e93042 (#627) (latest commit) we can do this:

#[derive(Debug, Trace, Finalize)]
struct Person {
    name: String,
    age: u32,
}

impl Person {
    fn say_hello(this: &Value, _: &[Value], ctx: &mut Interpreter) -> ResultValue {
        if let Some(object) = this.as_object() {
            if let Some(person) = object.downcast_ref::<Person>() {
                println!(
                    "Hello my name is {}, I'm {} years old",
                    person.name, person.age
                );
                return Ok(Value::undefined());
            }
        }
        ctx.throw_type_error("'this' is not a Person object")
    }
}

impl Class for Person {
    const NAME: &'static str = "Person";
    const LENGTH: usize = 2;

    fn constructor(this: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue {
        let name = ctx.to_string(&args.get(0).cloned().unwrap_or_default())?;
        let age = ctx.to_uint32(&args.get(1).cloned().unwrap_or_default())?;

        let person = Person {
            name: name.to_string(),
            age,
        };

        this.set_data(ObjectData::NativeObject(Box::new(person)));
    	Ok(this.clone())
    }

    fn methods(class: &mut ClassBuilder) -> ResultValue {
		// This puts it in `Person.prototype.sayHello`.
        class.method("sayHello", 0, Self::say_hello);
		// This puts it in `className.iAmAStaticMethod`.
        class.static_method("iAmAStaticMethod", 0, |_, _, _| {
        	println!("Hi o/");
        	Ok(Value::undefined())
        });

        Ok(Value::undefined())
    }
}

fn main() {
    let realm = Realm::create();
    let mut context = Interpreter::new(realm);

	// Initalizes, and registers the Class. 
    context.register_global_class::<Person>().unwrap();
    forward(
        &mut context,
        r"
		let person_instance = new Person('John', 19);
		person_instance.sayHello();
		Person.iAmAStaticMethod();
	");
}

This prints as expected:

Hello my name is John, I'm 19 years old
Hi o/

What do you think? @Razican @jasonwilliams @Lan2u

@HalidOdat HalidOdat changed the title Feature native object Feature native class objects (NativeObject and Class traits) Aug 15, 2020
@Razican
Copy link
Member

Razican commented Aug 15, 2020

What do you think? @Razican @jasonwilliams @Lan2u

I love this! It's very ergonomic and easy to use :)

About the API itself, I just have these of questions:

  • Should the API for register_global_class() use static or dynamic dispatch? The static dispatch might add too much code duplication that add some cache misses, but I don't think it will be relevant (this is usually only called when setting up the environment).
  • Do all classes/objects have a constructor? (didn't read the spec here)
  • What about the difference on things like new String() and String()?
  • I think we shouldn't use println!() to print stuff in the methods. We should add a Logger (maybe just the Printer?) in the context to do things such as console.log() or console.info(). This Logger should be customizable by API users in case they want to provide a logger that writes to a log file or a database (instead to stdout) - Implement an easily replaceable Printer for console #551. Probably not directly related to this PR, but something to have in mind.
  • If we would like to offer a C/C++ API, how could we wrap this?

@HalidOdat
Copy link
Member Author

HalidOdat commented Aug 15, 2020

Should the API for register_global_class() use static or dynamic dispatch? The static dispatch might add too much code duplication that add some cache misses, but I don't think it will be relevant (this is usually only called when setting up the environment).

I don't think this is going to be an issue either, I can make ClassBuilder::new a non-generic since that is the biggest function and all the other generic functions are small.

Do all classes/objects have a constructor? (didn't read the spec here)

Did not read the spec either 😄 , but the constructor is what is called when we do new Object() so there has to be a function that is called ( in builins/string/mod.rs it's make_string this is the constructor when we do new String())

What about the difference on things like new String() and String()?

As far as I know class constructors always require new keyword:

class X {}
x() // Uncaught TypeError: class constructors must be invoked with 'new'

I could add a CALLABLE to Class trait.

pub trait Class: NativeObject {
	const CALLABLE: bool = false; // this would default to false to match with javascript class.
}

we could have the same for CONSTRUCTABLE

If we would like to offer a C/C++ API, how could we wrap this?

I'm not that experienced with rust to C ffi. but this class is a wrapper around what we do in for example Array (calling make_constructor_fn and make_builtin_fn) we could expose those functions to C.

@Razican
Copy link
Member

Razican commented Aug 15, 2020

Do all classes/objects have a constructor? (didn't read the spec here)

Did not read the spec either smile , but the constructor is what is called when we do new Object() so there has to be a function that is called ( in builins/string/mod.rs it's make_string this is the constructor when we do new String())

What about the difference on things like new String() and String()?

As far as I know class constructors always require new keyword:

class X {}
x() // Uncaught TypeError: class constructors must be invoked with 'new'

I could add a CALLABLE to Class trait.

pub trait Class: NativeObject {
	const CALLABLE: bool = false; // this would default to false to match with javascript class.
}

we could have the same for CONSTRUCTABLE

I think @jasonwilliams can give us some insight here, since he worked with this at some point.

@HalidOdat
Copy link
Member Author

HalidOdat commented Aug 15, 2020

Now in the constructor, instead of this:

fn constructor(this: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue {
    let name = ctx.to_string(&args.get(0).cloned().unwrap_or_default())?;
    let age = ctx.to_uint32(&args.get(1).cloned().unwrap_or_default())?;

    let person = Person {
        name: name.to_string(),
 	    age,
    };

    this.set_data(ObjectData::NativeObject(Box::new(person)));
  	Ok(this.clone())
}

Instead of having to manually call .set_data() (if we don't this is a bug and can become a hard bug to identify), but now it is enforced by the type system. (Result<Self, Value>):

// _this is still avalable if we want to set properties (string, symbol) of the class instance.
fn constructor(_this: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Self, Value> {
    let name = ctx.to_string(&args.get(0).cloned().unwrap_or_default())?;
    let age = ctx.to_uint32(&args.get(1).cloned().unwrap_or_default())?;

    let person = Person {
        name: name.to_string(),
 	    age,
    };
  	Ok(person)
}

what do you think?

@github-actions
Copy link

Benchmark for eca45f4

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 382.1±7.75ns 376.1±5.55ns +1.60%
Arithmetic operations (Full) 248.2±7.67µs 244.4±7.70µs +1.55%
Array access (Execution) 8.3±0.53µs 8.2±0.18µs +1.22%
Array access (Full) 261.5±8.63µs 261.7±6.15µs -0.08%
Array creation (Execution) 3.4±0.08ms 3.3±0.10ms +3.03%
Array creation (Full) 3.7±0.06ms 3.7±0.08ms 0.00%
Array pop (Execution) 1229.1±53.83µs 1210.1±93.70µs +1.57%
Array pop (Full) 1566.2±37.36µs 1572.9±63.82µs -0.43%
Boolean Object Access (Execution) 4.3±0.18µs 4.3±0.10µs 0.00%
Boolean Object Access (Full) 256.5±10.72µs 253.9±3.94µs +1.02%
Create Realm 474.3±9.13ns 472.5±7.67ns +0.38%
Dynamic Object Property Access (Execution) 4.9±0.05µs 4.9±0.05µs 0.00%
Dynamic Object Property Access (Full) 253.9±9.10µs 253.2±3.74µs +0.28%
Expression (Lexer) 2.4±0.06µs 2.4±0.08µs 0.00%
Expression (Parser) 5.3±0.08µs 5.3±0.09µs 0.00%
Fibonacci (Execution) 863.0±14.39µs 888.6±23.44µs -2.88%
Fibonacci (Full) 1172.0±26.80µs 1185.8±38.85µs -1.16%
For loop (Execution) 22.4±0.72µs 22.1±0.42µs +1.36%
For loop (Full) 274.8±3.13µs 273.0±3.75µs +0.66%
For loop (Lexer) 5.3±0.18µs 5.3±0.11µs 0.00%
For loop (Parser) 14.2±0.29µs 14.0±0.25µs +1.43%
Goal Symbols (Parser) 8.5±0.18µs 8.5±0.35µs 0.00%
Hello World (Lexer) 843.2±17.23ns 832.7±54.30ns +1.26%
Hello World (Parser) 2.1±0.04µs 2.1±0.05µs 0.00%
Long file (Parser) 6.5±0.15ms 6.5±0.09ms 0.00%
Number Object Access (Execution) 3.4±0.20µs 3.4±0.19µs 0.00%
Number Object Access (Full) 249.5±7.45µs 252.6±9.15µs -1.23%
Object Creation (Execution) 4.1±0.06µs 4.1±0.06µs 0.00%
Object Creation (Full) 308.1±13.91µs 306.5±8.36µs +0.52%
RegExp (Execution) 66.0±3.40µs 66.3±2.62µs -0.45%
RegExp (Full) 405.3±14.54µs 412.5±44.29µs -1.75%
RegExp Literal (Execution) 68.1±1.70µs 67.7±2.33µs +0.59%
RegExp Literal (Full) 330.6±11.39µs 328.2±5.70µs +0.73%
RegExp Literal Creation (Execution) 64.8±1.25µs 66.0±2.20µs -1.82%
RegExp Literal Creation (Full) 400.1±4.83µs 401.3±11.60µs -0.30%
Static Object Property Access (Execution) 4.4±0.20µs 4.4±0.31µs 0.00%
Static Object Property Access (Full) 250.5±5.35µs 255.5±14.46µs -1.96%
String Object Access (Execution) 6.5±0.18µs 6.5±0.17µs 0.00%
String Object Access (Full) 256.1±6.86µs 257.2±7.50µs -0.43%
String comparison (Execution) 6.0±0.52µs 6.0±0.17µs 0.00%
String comparison (Full) 255.4±10.43µs 255.1±3.97µs +0.12%
String concatenation (Execution) 4.7±0.08µs 4.8±0.26µs -2.08%
String concatenation (Full) 256.6±10.73µs 251.5±2.51µs +2.03%
String copy (Execution) 3.4±0.06µs 3.5±0.05µs -2.86%
String copy (Full) 256.4±15.27µs 249.5±6.83µs +2.77%
Symbols (Execution) 2.8±0.09µs 2.8±0.04µs 0.00%
Symbols (Full) 239.0±14.29µs 232.4±5.87µs +2.84%

@github-actions
Copy link

Benchmark for a4e570f

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 367.3±28.64ns 321.6±21.35ns +14.21%
Arithmetic operations (Full) 218.0±15.71µs 229.0±14.49µs -4.80%
Array access (Execution) 7.6±0.43µs 7.5±0.50µs +1.33%
Array access (Full) 236.1±16.49µs 236.3±14.40µs -0.08%
Array creation (Execution) 2.8±0.17ms 2.8±0.14ms 0.00%
Array creation (Full) 3.1±0.15ms 3.4±0.17ms -8.82%
Array pop (Execution) 987.7±60.75µs 978.0±56.02µs +0.99%
Array pop (Full) 1297.2±74.13µs 1467.3±93.97µs -11.59%
Boolean Object Access (Execution) 3.9±0.26µs 3.8±0.27µs +2.63%
Boolean Object Access (Full) 232.7±14.46µs 247.4±13.74µs -5.94%
Create Realm 401.6±29.90ns 402.8±33.77ns -0.30%
Dynamic Object Property Access (Execution) 4.8±0.29µs 4.6±0.33µs +4.35%
Dynamic Object Property Access (Full) 230.9±16.59µs 257.7±17.95µs -10.40%
Expression (Lexer) 2.1±0.15µs 2.2±0.14µs -4.55%
Expression (Parser) 4.6±0.28µs 5.0±0.29µs -8.00%
Fibonacci (Execution) 864.3±47.06µs 879.3±47.49µs -1.71%
Fibonacci (Full) 1095.4±60.13µs 1095.3±65.57µs +0.01%
For loop (Execution) 20.7±1.73µs 20.3±1.24µs +1.97%
For loop (Full) 245.3±15.95µs 248.4±17.93µs -1.25%
For loop (Lexer) 4.4±0.25µs 4.9±0.35µs -10.20%
For loop (Parser) 12.4±0.69µs 13.3±1.04µs -6.77%
Goal Symbols (Parser) 7.6±0.50µs 8.2±0.64µs -7.32%
Hello World (Lexer) 748.6±54.75ns 770.7±55.70ns -2.87%
Hello World (Parser) 1853.2±114.54ns 2.1±0.11µs -11.75%
Long file (Parser) 5.8±0.25ms 6.0±0.29ms -3.33%
Number Object Access (Execution) 3.0±0.26µs 3.1±0.20µs -3.23%
Number Object Access (Full) 226.8±14.86µs 247.9±14.57µs -8.51%
Object Creation (Execution) 4.2±0.28µs 3.9±0.29µs +7.69%
Object Creation (Full) 267.6±14.96µs 301.2±16.43µs -11.16%
RegExp (Execution) 62.9±4.23µs 63.2±5.95µs -0.47%
RegExp (Full) 359.6±24.33µs 380.9±24.42µs -5.59%
RegExp Literal (Execution) 67.0±5.02µs 66.0±3.76µs +1.52%
RegExp Literal (Full) 306.4±21.75µs 315.6±25.29µs -2.92%
RegExp Literal Creation (Execution) 61.2±3.96µs 61.8±3.88µs -0.97%
RegExp Literal Creation (Full) 359.5±21.13µs 384.9±45.42µs -6.60%
Static Object Property Access (Execution) 4.4±0.27µs 4.2±0.25µs +4.76%
Static Object Property Access (Full) 232.5±16.30µs 249.8±12.92µs -6.93%
String Object Access (Execution) 5.8±0.36µs 6.1±0.65µs -4.92%
String Object Access (Full) 237.5±16.09µs 248.1±12.46µs -4.27%
String comparison (Execution) 5.4±0.34µs 5.4±0.35µs 0.00%
String comparison (Full) 231.0±13.32µs 257.1±13.62µs -10.15%
String concatenation (Execution) 4.4±0.30µs 4.6±0.27µs -4.35%
String concatenation (Full) 230.9±23.42µs 256.3±13.83µs -9.91%
String copy (Execution) 3.2±0.20µs 3.3±0.21µs -3.03%
String copy (Full) 221.8±14.04µs 245.8±16.50µs -9.76%
Symbols (Execution) 2.8±0.20µs 2.8±0.17µs 0.00%
Symbols (Full) 207.1±14.28µs 201.9±12.08µs +2.58%

@github-actions
Copy link

Benchmark for 3ab4b22

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 326.5±17.88ns 324.2±22.74ns +0.71%
Arithmetic operations (Full) 206.8±12.10µs 208.3±13.17µs -0.72%
Array access (Execution) 7.2±0.54µs 6.9±0.41µs +4.35%
Array access (Full) 222.7±12.91µs 228.2±16.11µs -2.41%
Array creation (Execution) 2.8±0.13ms 3.0±0.12ms -6.67%
Array creation (Full) 3.3±0.15ms 3.3±0.14ms 0.00%
Array pop (Execution) 988.5±79.59µs 1041.7±71.59µs -5.11%
Array pop (Full) 1398.0±77.35µs 1381.1±83.37µs +1.22%
Boolean Object Access (Execution) 3.5±0.21µs 3.6±0.19µs -2.78%
Boolean Object Access (Full) 220.9±11.92µs 220.0±14.23µs +0.41%
Create Realm 393.6±24.31ns 413.5±21.50ns -4.81%
Dynamic Object Property Access (Execution) 4.2±0.32µs 4.2±0.31µs 0.00%
Dynamic Object Property Access (Full) 228.8±20.74µs 217.5±13.92µs +5.20%
Expression (Lexer) 2.1±0.13µs 2.1±0.13µs 0.00%
Expression (Parser) 4.7±0.32µs 4.9±0.36µs -4.08%
Fibonacci (Execution) 744.4±45.88µs 747.9±54.72µs -0.47%
Fibonacci (Full) 1002.2±57.82µs 1004.1±69.83µs -0.19%
For loop (Execution) 19.2±1.26µs 18.8±1.24µs +2.13%
For loop (Full) 242.5±16.42µs 239.1±16.81µs +1.42%
For loop (Lexer) 4.6±0.32µs 4.6±0.31µs 0.00%
For loop (Parser) 12.2±0.76µs 12.5±0.81µs -2.40%
Goal Symbols (Parser) 7.4±0.36µs 7.4±0.49µs 0.00%
Hello World (Lexer) 723.7±53.90ns 713.0±41.89ns +1.50%
Hello World (Parser) 1849.0±124.58ns 1853.0±109.48ns -0.22%
Long file (Parser) 5.6±0.24ms 5.5±0.22ms +1.82%
Number Object Access (Execution) 2.9±0.22µs 2.9±0.23µs 0.00%
Number Object Access (Full) 210.8±15.52µs 218.5±14.19µs -3.52%
Object Creation (Execution) 3.6±0.24µs 3.6±0.24µs 0.00%
Object Creation (Full) 258.5±19.13µs 257.9±14.79µs +0.23%
RegExp (Execution) 57.1±4.03µs 56.7±4.54µs +0.71%
RegExp (Full) 345.7±22.90µs 349.6±24.67µs -1.12%
RegExp Literal (Execution) 59.3±3.54µs 58.6±3.85µs +1.19%
RegExp Literal (Full) 280.9±18.99µs 295.2±23.02µs -4.84%
RegExp Literal Creation (Execution) 58.3±4.24µs 59.1±4.48µs -1.35%
RegExp Literal Creation (Full) 346.4±21.81µs 346.8±22.92µs -0.12%
Static Object Property Access (Execution) 3.9±0.28µs 3.7±0.27µs +5.41%
Static Object Property Access (Full) 219.5±17.09µs 217.2±14.95µs +1.06%
String Object Access (Execution) 5.6±0.57µs 5.5±0.38µs +1.82%
String Object Access (Full) 218.1±16.74µs 233.4±21.68µs -6.56%
String comparison (Execution) 5.0±0.49µs 5.1±0.36µs -1.96%
String comparison (Full) 214.8±11.99µs 217.6±12.82µs -1.29%
String concatenation (Execution) 4.1±0.25µs 4.1±0.26µs 0.00%
String concatenation (Full) 217.4±13.78µs 215.1±14.75µs +1.07%
String copy (Execution) 3.0±0.27µs 3.0±0.24µs 0.00%
String copy (Full) 213.2±14.30µs 217.2±16.43µs -1.84%
Symbols (Execution) 2.5±0.17µs 2.4±0.18µs +4.17%
Symbols (Full) 202.3±13.34µs 198.3±11.72µs +2.02%

@Razican
Copy link
Member

Razican commented Aug 16, 2020

what do you think?

Much better! This also allows us to change the set_data() API in the future without it being a breaking change :)

@HalidOdat HalidOdat added this to the v0.10.0 milestone Aug 16, 2020
@github-actions
Copy link

Benchmark for 4a9ec1e

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 380.5±7.83ns 375.1±8.98ns +1.44%
Arithmetic operations (Full) 232.8±5.91µs 235.6±10.62µs -1.19%
Array access (Execution) 8.1±0.23µs 8.0±0.24µs +1.25%
Array access (Full) 262.0±11.29µs 251.8±11.55µs +4.05%
Array creation (Execution) 3.3±0.07ms 3.2±0.09ms +3.13%
Array creation (Full) 3.7±0.09ms 3.6±0.08ms +2.78%
Array pop (Execution) 1152.2±60.32µs 1153.1±36.71µs -0.08%
Array pop (Full) 1546.8±46.47µs 1563.2±36.85µs -1.05%
Boolean Object Access (Execution) 4.2±0.08µs 4.2±0.18µs 0.00%
Boolean Object Access (Full) 246.6±6.15µs 242.9±9.11µs +1.52%
Create Realm 459.3±12.09ns 472.6±17.45ns -2.81%
Dynamic Object Property Access (Execution) 4.7±0.14µs 4.8±0.15µs -2.08%
Dynamic Object Property Access (Full) 245.7±6.50µs 250.6±7.89µs -1.96%
Expression (Lexer) 2.3±0.05µs 2.3±0.08µs 0.00%
Expression (Parser) 5.3±0.12µs 5.2±0.12µs +1.92%
Fibonacci (Execution) 866.3±19.89µs 844.4±21.14µs +2.59%
Fibonacci (Full) 1158.8±45.27µs 1135.3±72.30µs +2.07%
For loop (Execution) 22.1±0.43µs 21.8±0.61µs +1.38%
For loop (Full) 273.0±7.09µs 267.8±8.88µs +1.94%
For loop (Lexer) 5.1±0.20µs 5.2±0.40µs -1.92%
For loop (Parser) 13.8±0.29µs 13.8±0.53µs 0.00%
Goal Symbols (Parser) 8.1±0.30µs 8.3±0.24µs -2.41%
Hello World (Lexer) 792.2±26.62ns 816.0±22.44ns -2.92%
Hello World (Parser) 2.1±0.09µs 2.1±0.07µs 0.00%
Long file (Parser) 6.1±0.13ms 6.1±0.11ms 0.00%
Number Object Access (Execution) 3.3±0.14µs 3.3±0.14µs 0.00%
Number Object Access (Full) 246.9±6.90µs 239.6±7.87µs +3.05%
Object Creation (Execution) 4.0±0.15µs 4.0±0.10µs 0.00%
Object Creation (Full) 291.9±7.42µs 294.6±8.14µs -0.92%
RegExp (Execution) 65.2±3.19µs 61.6±1.82µs +5.84%
RegExp (Full) 393.9±8.80µs 385.2±10.02µs +2.26%
RegExp Literal (Execution) 67.9±4.18µs 65.5±2.63µs +3.66%
RegExp Literal (Full) 316.5±10.20µs 320.5±10.23µs -1.25%
RegExp Literal Creation (Execution) 64.6±2.02µs 62.1±2.18µs +4.03%
RegExp Literal Creation (Full) 395.6±12.72µs 389.3±9.63µs +1.62%
Static Object Property Access (Execution) 4.3±0.13µs 4.2±0.12µs +2.38%
Static Object Property Access (Full) 244.0±8.73µs 246.8±8.68µs -1.13%
String Object Access (Execution) 6.3±0.17µs 6.3±0.15µs 0.00%
String Object Access (Full) 245.7±7.32µs 246.7±8.94µs -0.41%
String comparison (Execution) 5.9±0.22µs 5.8±0.19µs +1.72%
String comparison (Full) 248.2±8.11µs 244.5±6.73µs +1.51%
String concatenation (Execution) 4.7±0.16µs 4.6±0.12µs +2.17%
String concatenation (Full) 243.1±11.79µs 242.9±6.46µs +0.08%
String copy (Execution) 3.4±0.08µs 3.5±0.07µs -2.86%
String copy (Full) 238.1±6.72µs 237.8±9.00µs +0.13%
Symbols (Execution) 2.8±0.04µs 2.8±0.06µs 0.00%
Symbols (Full) 227.5±5.59µs 227.3±16.59µs +0.09%

@jasonwilliams
Copy link
Member

jasonwilliams commented Aug 17, 2020

Do all classes/objects have a constructor? (didn't read the spec here)

No, constructors and objects are completely separate. A constructor is just a function that’s given an object (this) to then populate and return.
Usually constructors just set the prototype of the object.

You can have objects from scratch with no constructor at all.
Classes are just syntactic sugar so they behave the same.

This is where things get interesting!
The constructor and the function are the same! I thought they were 2 separate implementations but they’re the same function.
The way it works is that the function sets the correct value to this but also returns a value.
Let’s use String as an example..

For ‘new String()’: this is provided and the function sets this to be the string instance and that is used ( the return value is ignored)

For ‘String()’: the return value is used and returned to the assignment, all of the this stuff is ignored.

For the rest I’ll have to look when I’m back at my desk, but constructable sounds about right, I think this exists in the spec.

@github-actions
Copy link

Benchmark for 7d99582

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 394.2±11.42ns 392.3±29.48ns +0.48%
Arithmetic operations (Full) 246.7±9.65µs 246.1±6.23µs +0.24%
Array access (Execution) 8.6±0.44µs 8.4±0.51µs +2.38%
Array access (Full) 265.0±7.99µs 275.3±11.57µs -3.74%
Array creation (Execution) 3.5±0.12ms 3.4±0.09ms +2.94%
Array creation (Full) 3.8±0.10ms 3.9±0.11ms -2.56%
Array pop (Execution) 1239.5±33.68µs 1229.0±86.32µs +0.85%
Array pop (Full) 1627.0±65.42µs 1635.6±68.84µs -0.53%
Boolean Object Access (Execution) 4.2±0.11µs 4.3±0.15µs -2.33%
Boolean Object Access (Full) 257.2±15.42µs 261.7±29.28µs -1.72%
Create Realm 477.0±19.02ns 466.1±18.27ns +2.34%
Dynamic Object Property Access (Execution) 5.2±0.25µs 5.2±0.21µs 0.00%
Dynamic Object Property Access (Full) 258.0±12.08µs 270.7±14.53µs -4.69%
Expression (Lexer) 2.4±0.10µs 2.5±0.15µs -4.00%
Expression (Parser) 5.5±0.52µs 5.4±0.22µs +1.85%
Fibonacci (Execution) 867.0±19.79µs 882.8±24.24µs -1.79%
Fibonacci (Full) 1183.8±99.83µs 1222.3±124.39µs -3.15%
For loop (Execution) 23.3±0.92µs 22.8±0.73µs +2.19%
For loop (Full) 283.6±8.80µs 293.6±12.61µs -3.41%
For loop (Lexer) 5.3±0.12µs 5.4±0.27µs -1.85%
For loop (Parser) 14.3±0.34µs 14.5±0.78µs -1.38%
Goal Symbols (Parser) 8.6±0.24µs 8.7±0.66µs -1.15%
Hello World (Lexer) 827.9±20.38ns 847.3±63.50ns -2.29%
Hello World (Parser) 2.2±0.19µs 2.2±0.09µs 0.00%
Long file (Parser) 6.5±0.14ms 6.7±0.29ms -2.99%
Number Object Access (Execution) 3.4±0.24µs 3.4±0.18µs 0.00%
Number Object Access (Full) 250.2±6.92µs 256.8±15.95µs -2.57%
Object Creation (Execution) 4.2±0.14µs 4.3±0.24µs -2.33%
Object Creation (Full) 318.9±36.27µs 314.4±22.25µs +1.43%
RegExp (Execution) 67.8±3.83µs 66.0±2.03µs +2.73%
RegExp (Full) 415.3±14.24µs 412.7±11.79µs +0.63%
RegExp Literal (Execution) 72.2±3.93µs 72.5±4.16µs -0.41%
RegExp Literal (Full) 344.7±15.61µs 334.5±8.76µs +3.05%
RegExp Literal Creation (Execution) 68.4±8.72µs 69.0±12.57µs -0.87%
RegExp Literal Creation (Full) 408.2±16.20µs 412.9±18.78µs -1.14%
Static Object Property Access (Execution) 4.5±0.57µs 4.5±0.18µs 0.00%
Static Object Property Access (Full) 256.0±8.02µs 262.5±20.21µs -2.48%
String Object Access (Execution) 6.6±0.28µs 6.6±0.29µs 0.00%
String Object Access (Full) 258.8±7.67µs 261.7±18.61µs -1.11%
String comparison (Execution) 5.9±0.16µs 6.2±0.36µs -4.84%
String comparison (Full) 258.9±8.99µs 262.1±11.49µs -1.22%
String concatenation (Execution) 4.9±0.28µs 4.9±0.09µs 0.00%
String concatenation (Full) 256.4±14.57µs 256.6±12.36µs -0.08%
String copy (Execution) 3.5±0.18µs 3.6±0.15µs -2.78%
String copy (Full) 251.8±19.29µs 259.5±11.21µs -2.97%
Symbols (Execution) 2.9±0.08µs 3.0±0.11µs -3.33%
Symbols (Full) 233.2±7.54µs 240.4±10.81µs -3.00%

@github-actions
Copy link

Benchmark for d6565c7

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 349.9±27.40ns 335.1±17.02ns +4.42%
Arithmetic operations (Full) 239.3±12.04µs 237.4±11.13µs +0.80%
Array access (Execution) 8.9±0.67µs 8.6±0.67µs +3.49%
Array access (Full) 254.6±13.83µs 249.1±12.46µs +2.21%
Array creation (Execution) 3.2±0.11ms 3.0±0.12ms +6.67%
Array creation (Full) 3.5±0.20ms 3.4±0.13ms +2.94%
Array pop (Execution) 1105.4±50.63µs 1067.9±73.13µs +3.51%
Array pop (Full) 1431.5±69.16µs 1444.9±108.82µs -0.93%
Boolean Object Access (Execution) 4.3±0.22µs 4.1±0.26µs +4.88%
Boolean Object Access (Full) 247.3±14.76µs 243.5±11.45µs +1.56%
Create Realm 443.6±21.17ns 426.1±17.60ns +4.11%
Dynamic Object Property Access (Execution) 5.5±0.20µs 5.2±0.27µs +5.77%
Dynamic Object Property Access (Full) 254.3±20.70µs 250.5±12.35µs +1.52%
Expression (Lexer) 2.2±0.13µs 2.2±0.13µs 0.00%
Expression (Parser) 5.3±0.28µs 4.9±0.35µs +8.16%
Fibonacci (Execution) 976.0±41.35µs 900.6±40.07µs +8.37%
Fibonacci (Full) 1190.2±64.43µs 1194.1±73.45µs -0.33%
For loop (Execution) 23.2±1.06µs 22.2±1.06µs +4.50%
For loop (Full) 270.1±22.71µs 274.2±19.31µs -1.50%
For loop (Lexer) 5.0±0.28µs 4.9±0.29µs +2.04%
For loop (Parser) 13.1±0.73µs 13.0±0.74µs +0.77%
Goal Symbols (Parser) 8.0±0.53µs 7.9±0.43µs +1.27%
Hello World (Lexer) 822.4±37.74ns 817.2±39.16ns +0.64%
Hello World (Parser) 2.0±0.11µs 1992.5±118.51ns +0.38%
Long file (Parser) 6.1±0.23ms 6.1±0.22ms 0.00%
Number Object Access (Execution) 3.6±0.83µs 3.2±0.15µs +12.50%
Number Object Access (Full) 244.0±12.97µs 245.9±15.57µs -0.77%
Object Creation (Execution) 4.6±0.17µs 4.4±0.24µs +4.55%
Object Creation (Full) 299.3±19.46µs 293.1±19.79µs +2.12%
RegExp (Execution) 69.4±3.69µs 66.9±4.79µs +3.74%
RegExp (Full) 397.1±18.63µs 393.3±20.89µs +0.97%
RegExp Literal (Execution) 75.5±4.96µs 70.7±3.92µs +6.79%
RegExp Literal (Full) 329.4±24.50µs 335.5±16.12µs -1.82%
RegExp Literal Creation (Execution) 69.4±3.15µs 67.0±4.00µs +3.58%
RegExp Literal Creation (Full) 396.7±18.13µs 393.3±21.97µs +0.86%
Static Object Property Access (Execution) 4.9±0.16µs 4.7±0.23µs +4.26%
Static Object Property Access (Full) 249.4±12.42µs 251.1±16.04µs -0.68%
String Object Access (Execution) 6.5±0.39µs 6.4±0.42µs +1.56%
String Object Access (Full) 250.6±15.76µs 249.7±12.81µs +0.36%
String comparison (Execution) 6.0±0.22µs 5.8±0.32µs +3.45%
String comparison (Full) 252.2±14.79µs 257.2±17.93µs -1.94%
String concatenation (Execution) 4.9±0.21µs 4.7±0.24µs +4.26%
String concatenation (Full) 244.9±18.18µs 247.3±18.74µs -0.97%
String copy (Execution) 3.9±0.19µs 3.7±0.27µs +5.41%
String copy (Full) 241.9±11.63µs 244.7±9.06µs -1.14%
Symbols (Execution) 3.1±0.28µs 3.0±0.13µs +3.33%
Symbols (Full) 234.0±13.64µs 223.8±12.17µs +4.56%

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.

It's looking pretty good :) Do you think we should use this for our own internal objects?

boa/src/builtins/object/internal_methods.rs Show resolved Hide resolved
boa/src/builtins/property/attribute/mod.rs Outdated Show resolved Hide resolved
boa/examples/classes.rs Outdated Show resolved Hide resolved
@Razican Razican mentioned this pull request Aug 19, 2020
@HalidOdat
Copy link
Member Author

HalidOdat commented Aug 19, 2020

It's looking pretty good :) Do you think we should use this for our own internal objects?

It is is possible just needs some changes also some missing things are the ability to add static properties and prototype properties,

@Razican
Copy link
Member

Razican commented Aug 19, 2020

It's looking pretty good :) Do you think we should use this for our own internal objects?

It is is possible just needs some changes also some missing things are the ability to add static properties and prototype properties,

In that case, I think we should leave that for a future PR and merge this as soon as you feel it's ready :)

@github-actions
Copy link

Benchmark for 272e2e9

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 356.9±17.47ns 374.5±6.18ns -4.70%
Arithmetic operations (Full) 246.3±7.09µs 243.5±3.41µs +1.15%
Array access (Execution) 8.4±0.32µs 8.4±0.18µs 0.00%
Array access (Full) 264.2±7.58µs 264.7±5.72µs -0.19%
Array creation (Execution) 3.4±0.05ms 3.6±0.07ms -5.56%
Array creation (Full) 3.7±0.06ms 3.8±0.05ms -2.63%
Array pop (Execution) 1242.4±32.35µs 1286.2±29.12µs -3.41%
Array pop (Full) 1522.2±20.47µs 1585.8±28.80µs -4.01%
Boolean Object Access (Execution) 4.2±0.11µs 4.3±0.12µs -2.33%
Boolean Object Access (Full) 254.2±6.43µs 254.0±4.08µs +0.08%
Create Realm 472.2±21.40ns 455.7±8.10ns +3.62%
Dynamic Object Property Access (Execution) 5.1±0.12µs 5.2±0.24µs -1.92%
Dynamic Object Property Access (Full) 253.3±5.52µs 262.5±11.33µs -3.50%
Expression (Lexer) 2.4±0.02µs 2.4±0.06µs 0.00%
Expression (Parser) 5.6±0.42µs 5.5±0.17µs +1.82%
Fibonacci (Execution) 870.9±17.97µs 886.2±18.20µs -1.73%
Fibonacci (Full) 1193.4±24.48µs 1181.7±36.55µs +0.99%
For loop (Execution) 23.1±0.81µs 22.1±0.27µs +4.52%
For loop (Full) 280.0±8.82µs 281.0±7.42µs -0.36%
For loop (Lexer) 5.4±0.08µs 5.4±0.12µs 0.00%
For loop (Parser) 14.2±0.18µs 14.2±0.45µs 0.00%
Goal Symbols (Parser) 8.6±0.19µs 8.6±0.21µs 0.00%
Hello World (Lexer) 853.8±10.06ns 844.7±19.47ns +1.08%
Hello World (Parser) 2.2±0.03µs 2.2±0.03µs 0.00%
Long file (Parser) 6.4±0.07ms 6.5±0.13ms -1.54%
Number Object Access (Execution) 3.4±0.06µs 3.4±0.11µs 0.00%
Number Object Access (Full) 253.8±7.34µs 251.4±4.77µs +0.95%
Object Creation (Execution) 4.4±0.06µs 4.4±0.07µs 0.00%
Object Creation (Full) 304.1±7.55µs 306.7±4.70µs -0.85%
RegExp (Execution) 62.4±3.46µs 66.6±1.96µs -6.31%
RegExp (Full) 411.5±11.16µs 406.0±6.22µs +1.35%
RegExp Literal (Execution) 70.1±1.43µs 70.0±1.78µs +0.14%
RegExp Literal (Full) 334.3±4.86µs 336.3±30.90µs -0.59%
RegExp Literal Creation (Execution) 67.0±1.76µs 66.1±1.85µs +1.36%
RegExp Literal Creation (Full) 408.9±6.50µs 407.4±19.25µs +0.37%
Static Object Property Access (Execution) 4.6±0.08µs 4.7±0.13µs -2.13%
Static Object Property Access (Full) 250.6±9.08µs 258.5±8.76µs -3.06%
String Object Access (Execution) 6.4±0.17µs 6.5±0.11µs -1.54%
String Object Access (Full) 256.6±6.67µs 254.9±5.76µs +0.67%
String comparison (Execution) 5.9±0.13µs 5.9±0.09µs 0.00%
String comparison (Full) 258.3±6.02µs 260.3±11.56µs -0.77%
String concatenation (Execution) 4.8±0.08µs 4.8±0.26µs 0.00%
String concatenation (Full) 251.1±2.72µs 249.1±4.35µs +0.80%
String copy (Execution) 3.6±0.08µs 3.6±0.22µs 0.00%
String copy (Full) 248.8±6.21µs 249.9±8.36µs -0.44%
Symbols (Execution) 2.9±0.13µs 3.0±0.08µs -3.33%
Symbols (Full) 230.7±5.48µs 236.5±4.36µs -2.45%

@HalidOdat
Copy link
Member Author

Added the ability to add inherited and static properties as discussed previously.

This is ready for review/merge :)

@github-actions
Copy link

Benchmark for 57b5c9d

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 356.9±9.26ns 351.9±15.18ns +1.42%
Arithmetic operations (Full) 274.5±18.80µs 245.4±9.62µs +11.86%
Array access (Execution) 7.9±0.32µs 8.3±0.57µs -4.82%
Array access (Full) 273.1±9.61µs 276.6±9.94µs -1.27%
Array creation (Execution) 3.1±0.19ms 3.3±0.15ms -6.06%
Array creation (Full) 3.8±0.15ms 3.5±0.11ms +8.57%
Array pop (Execution) 1101.3±71.32µs 1103.8±46.98µs -0.23%
Array pop (Full) 1613.8±60.00µs 1502.5±46.66µs +7.41%
Boolean Object Access (Execution) 4.8±0.19µs 5.1±0.40µs -5.88%
Boolean Object Access (Full) 263.3±10.33µs 253.9±10.98µs +3.70%
Clean js (Execution) 735.6±54.74µs 713.6±25.72µs +3.08%
Clean js (Full) 1051.9±32.95µs 1051.0±43.23µs +0.09%
Clean js (Parser) 26.7±1.13µs 24.1±0.93µs +10.79%
Create Realm 433.3±20.15ns 459.5±13.67ns -5.70%
Dynamic Object Property Access (Execution) 5.4±0.42µs 5.4±0.19µs 0.00%
Dynamic Object Property Access (Full) 271.4±8.41µs 265.4±10.64µs +2.26%
Expression (Lexer) 2.4±0.10µs 2.3±0.10µs +4.35%
Expression (Parser) 5.3±0.22µs 5.1±0.26µs +3.92%
Fibonacci (Execution) 853.3±55.24µs 860.3±26.86µs -0.81%
Fibonacci (Full) 1177.9±56.65µs 1159.1±48.84µs +1.62%
For loop (Execution) 22.6±0.99µs 22.7±0.72µs -0.44%
For loop (Full) 298.5±18.89µs 293.6±16.45µs +1.67%
For loop (Lexer) 4.2±0.14µs 4.0±0.15µs +5.00%
For loop (Parser) 12.6±0.54µs 11.9±0.86µs +5.88%
Goal Symbols (Parser) 8.4±0.40µs 8.3±0.27µs +1.20%
Hello World (Lexer) 887.8±28.70ns 800.5±27.22ns +10.91%
Hello World (Parser) 2.1±0.13µs 2.0±0.10µs +5.00%
Long file (Parser) 6.5±0.25ms 6.0±0.22ms +8.33%
Mini js (Execution) 651.6±31.62µs 625.8±22.75µs +4.12%
Mini js (Full) 967.3±32.11µs 909.8±34.24µs +6.32%
Mini js (Parser) 22.1±0.90µs 21.9±0.72µs +0.91%
Number Object Access (Execution) 3.8±0.18µs 3.7±0.13µs +2.70%
Number Object Access (Full) 269.6±15.74µs 247.2±10.07µs +9.06%
Object Creation (Execution) 4.5±0.18µs 4.6±0.21µs -2.17%
Object Creation (Full) 332.5±23.14µs 313.4±12.59µs +6.09%
RegExp (Execution) 70.7±4.02µs 71.8±4.41µs -1.53%
RegExp (Full) 425.2±19.60µs 407.3±18.68µs +4.39%
RegExp Literal (Execution) 72.7±2.90µs 70.9±2.88µs +2.54%
RegExp Literal (Full) 353.1±13.34µs 330.8±11.94µs +6.74%
RegExp Literal Creation (Execution) 65.9±2.87µs 66.4±2.69µs -0.75%
RegExp Literal Creation (Full) 429.6±14.53µs 410.0±31.50µs +4.78%
Static Object Property Access (Execution) 4.7±0.19µs 4.8±0.16µs -2.08%
Static Object Property Access (Full) 261.5±9.81µs 260.6±10.03µs +0.35%
String Object Access (Execution) 7.1±0.19µs 6.7±0.31µs +5.97%
String Object Access (Full) 266.7±11.56µs 252.1±9.75µs +5.79%
String comparison (Execution) 6.4±0.21µs 6.4±0.22µs 0.00%
String comparison (Full) 277.8±13.73µs 253.2±12.61µs +9.72%
String concatenation (Execution) 5.3±0.21µs 5.3±0.20µs 0.00%
String concatenation (Full) 272.1±21.86µs 269.6±16.37µs +0.93%
String copy (Execution) 4.2±0.17µs 3.8±0.12µs +10.53%
String copy (Full) 255.6±12.62µs 251.0±10.10µs +1.83%
Symbols (Execution) 3.1±0.10µs 3.2±0.10µs -3.13%
Symbols (Full) 240.2±11.28µs 225.5±8.21µs +6.52%

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! I think it would benefit from a bit more of documentation, since it will be our first "new API".

boa/src/builtins/object/mod.rs Outdated Show resolved Hide resolved
boa/src/exec/mod.rs Show resolved Hide resolved
boa/src/builtins/object/mod.rs Show resolved Hide resolved
boa/src/builtins/object/mod.rs Outdated Show resolved Hide resolved
boa/src/builtins/object/internal_methods.rs Show resolved Hide resolved
boa/examples/classes.rs Show resolved Hide resolved
@HalidOdat HalidOdat requested a review from Razican August 21, 2020 19:27
@github-actions
Copy link

Benchmark for 1e1e424

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 366.4±14.21ns 349.7±17.16ns +4.78%
Arithmetic operations (Full) 243.6±6.37µs 239.8±9.35µs +1.58%
Array access (Execution) 7.9±0.43µs 7.7±0.43µs +2.60%
Array access (Full) 252.0±10.87µs 255.4±9.85µs -1.33%
Array creation (Execution) 3.3±0.09ms 3.3±0.16ms 0.00%
Array creation (Full) 3.5±0.11ms 3.5±0.17ms 0.00%
Array pop (Execution) 1172.0±41.54µs 1127.5±41.86µs +3.95%
Array pop (Full) 1493.6±42.70µs 1501.5±72.92µs -0.53%
Boolean Object Access (Execution) 4.6±0.21µs 4.6±0.23µs 0.00%
Boolean Object Access (Full) 247.8±9.95µs 245.8±10.94µs +0.81%
Clean js (Execution) 725.6±26.12µs 703.9±30.88µs +3.08%
Clean js (Full) 1008.2±31.62µs 970.4±38.25µs +3.90%
Clean js (Parser) 22.9±1.13µs 24.0±1.20µs -4.58%
Create Realm 435.4±14.62ns 454.8±15.30ns -4.27%
Dynamic Object Property Access (Execution) 5.0±0.23µs 5.2±0.24µs -3.85%
Dynamic Object Property Access (Full) 248.8±8.67µs 260.2±22.98µs -4.38%
Expression (Lexer) 2.3±0.06µs 2.3±0.07µs 0.00%
Expression (Parser) 5.1±0.14µs 5.3±0.29µs -3.77%
Fibonacci (Execution) 765.1±25.23µs 760.3±30.41µs +0.63%
Fibonacci (Full) 1052.4±48.15µs 1036.7±35.69µs +1.51%
For loop (Execution) 21.6±0.95µs 21.4±2.53µs +0.93%
For loop (Full) 267.9±11.93µs 266.5±10.11µs +0.53%
For loop (Lexer) 4.2±0.14µs 4.1±0.16µs +2.44%
For loop (Parser) 12.1±1.00µs 12.2±0.65µs -0.82%
Goal Symbols (Parser) 8.0±0.36µs 8.3±0.35µs -3.61%
Hello World (Lexer) 834.3±35.60ns 823.2±39.44ns +1.35%
Hello World (Parser) 2.1±0.07µs 2.1±0.11µs 0.00%
Long file (Parser) 6.1±0.19ms 6.1±0.23ms 0.00%
Mini js (Execution) 631.8±22.93µs 659.9±26.61µs -4.26%
Mini js (Full) 891.0±34.42µs 886.2±35.46µs +0.54%
Mini js (Parser) 21.1±0.86µs 21.3±0.57µs -0.94%
Number Object Access (Execution) 3.6±0.16µs 3.6±0.39µs 0.00%
Number Object Access (Full) 239.9±10.68µs 248.4±9.36µs -3.42%
Object Creation (Execution) 4.4±0.16µs 4.3±0.18µs +2.33%
Object Creation (Full) 298.4±16.89µs 292.8±14.35µs +1.91%
RegExp (Execution) 63.2±3.26µs 62.6±3.42µs +0.96%
RegExp (Full) 406.8±13.72µs 384.3±15.64µs +5.85%
RegExp Literal (Execution) 67.9±3.50µs 67.2±5.13µs +1.04%
RegExp Literal (Full) 316.0±15.81µs 315.7±13.15µs +0.10%
RegExp Literal Creation (Execution) 64.5±3.11µs 63.8±2.44µs +1.10%
RegExp Literal Creation (Full) 400.1±10.24µs 388.5±20.05µs +2.99%
Static Object Property Access (Execution) 4.4±0.22µs 4.7±0.25µs -6.38%
Static Object Property Access (Full) 247.1±12.93µs 253.2±15.15µs -2.41%
String Object Access (Execution) 6.5±0.28µs 6.7±0.49µs -2.99%
String Object Access (Full) 247.9±12.00µs 246.5±7.43µs +0.57%
String comparison (Execution) 6.1±0.30µs 6.1±0.26µs 0.00%
String comparison (Full) 249.6±8.17µs 248.8±8.07µs +0.32%
String concatenation (Execution) 4.9±0.22µs 4.7±0.19µs +4.26%
String concatenation (Full) 247.4±9.76µs 244.9±9.38µs +1.02%
String copy (Execution) 3.7±0.17µs 3.6±0.14µs +2.78%
String copy (Full) 239.2±9.98µs 239.8±8.59µs -0.25%
Symbols (Execution) 3.0±0.15µs 3.0±0.14µs 0.00%
Symbols (Full) 227.3±9.38µs 224.4±10.67µs +1.29%

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 good from my side, just a comment for my understanding :)

boa/src/builtins/object/mod.rs Show resolved Hide resolved
@github-actions
Copy link

Benchmark for 1985c78

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 361.6±35.61ns 341.9±23.63ns +5.76%
Arithmetic operations (Full) 223.1±15.72µs 235.5±11.56µs -5.27%
Array access (Execution) 8.8±0.59µs 7.7±0.58µs +14.29%
Array access (Full) 290.0±17.06µs 273.7±23.51µs +5.96%
Array creation (Execution) 3.2±0.17ms 3.0±0.19ms +6.67%
Array creation (Full) 3.8±0.13ms 3.2±0.18ms +18.75%
Array pop (Execution) 1127.0±60.38µs 1057.6±78.70µs +6.56%
Array pop (Full) 1486.9±81.37µs 1387.7±94.86µs +7.15%
Boolean Object Access (Execution) 5.1±0.30µs 5.4±0.53µs -5.56%
Boolean Object Access (Full) 252.9±15.09µs 256.1±12.48µs -1.25%
Clean js (Execution) 728.0±47.74µs 700.9±104.77µs +3.87%
Clean js (Full) 890.8±55.04µs 931.5±54.72µs -4.37%
Clean js (Parser) 33.5±2.82µs 36.2±2.00µs -7.46%
Create Realm 442.9±30.71ns 414.2±28.52ns +6.93%
Dynamic Object Property Access (Execution) 5.7±0.28µs 5.9±0.62µs -3.39%
Dynamic Object Property Access (Full) 248.4±15.27µs 271.5±14.94µs -8.51%
Expression (Parser) 6.4±0.77µs 6.3±0.27µs +1.59%
Fibonacci (Execution) 904.2±37.29µs 884.4±44.29µs +2.24%
Fibonacci (Full) 1157.3±80.46µs 1036.1±57.87µs +11.70%
For loop (Execution) 22.7±1.44µs 21.5±1.59µs +5.58%
For loop (Full) 278.6±18.53µs 290.0±16.76µs -3.93%
For loop (Parser) 16.6±1.49µs 17.1±0.99µs -2.92%
Goal Symbols (Parser) 11.0±0.80µs 11.6±1.05µs -5.17%
Hello World (Parser) 2.7±0.21µs 2.8±0.16µs -3.57%
Long file (Parser) 718.5±50.11ns 748.0±41.68ns -3.94%
Mini js (Execution) 611.9±39.63µs 677.1±137.58µs -9.63%
Mini js (Full) 821.7±51.20µs 881.6±39.38µs -6.79%
Mini js (Parser) 31.1±2.21µs 30.0±1.82µs +3.67%
Number Object Access (Execution) 4.2±0.21µs 3.9±0.28µs +7.69%
Number Object Access (Full) 255.3±20.34µs 254.7±13.62µs +0.24%
Object Creation (Execution) 4.9±0.26µs 4.6±0.30µs +6.52%
Object Creation (Full) 309.0±23.49µs 307.5±36.47µs +0.49%
RegExp (Execution) 69.6±4.19µs 64.7±4.64µs +7.57%
RegExp (Full) 379.1±20.59µs 391.5±20.61µs -3.17%
RegExp Literal (Execution) 74.9±4.22µs 72.6±8.09µs +3.17%
RegExp Literal (Full) 319.4±20.89µs 315.6±16.80µs +1.20%
RegExp Literal Creation (Execution) 70.8±5.29µs 67.7±4.56µs +4.58%
RegExp Literal Creation (Full) 403.7±18.94µs 412.4±20.30µs -2.11%
Static Object Property Access (Execution) 5.3±0.29µs 5.3±0.54µs 0.00%
Static Object Property Access (Full) 254.0±16.92µs 266.5±22.34µs -4.69%
String Object Access (Execution) 6.9±0.55µs 6.9±0.40µs 0.00%
String Object Access (Full) 263.3±15.69µs 267.4±16.96µs -1.53%
String comparison (Execution) 6.0±0.50µs 6.3±0.43µs -4.76%
String comparison (Full) 253.7±17.72µs 273.7±17.36µs -7.31%
String concatenation (Execution) 5.2±0.31µs 5.2±0.24µs 0.00%
String concatenation (Full) 239.2±17.59µs 256.4±19.33µs -6.71%
String copy (Execution) 3.9±0.31µs 4.1±0.26µs -4.88%
String copy (Full) 250.9±20.76µs 245.0±15.65µs +2.41%
Symbols (Execution) 3.4±0.16µs 3.2±0.26µs +6.25%
Symbols (Full) 234.1±12.46µs 239.9±16.65µs -2.42%

@github-actions
Copy link

Benchmark for 49fda3b

Click to view benchmark
Test PR Benchmark Master Benchmark %
Arithmetic operations (Execution) 403.7±37.01ns 365.2±11.27ns +10.54%
Arithmetic operations (Full) 246.4±12.51µs 244.5±8.22µs +0.78%
Array access (Execution) 8.3±0.35µs 8.0±0.40µs +3.75%
Array access (Full) 272.1±10.58µs 269.3±12.21µs +1.04%
Array creation (Execution) 3.7±0.23ms 3.3±0.08ms +12.12%
Array creation (Full) 3.8±0.15ms 3.7±0.12ms +2.70%
Array pop (Execution) 1313.6±145.76µs 1176.9±59.55µs +11.62%
Array pop (Full) 1822.7±225.15µs 1669.2±72.21µs +9.20%
Boolean Object Access (Execution) 5.2±0.50µs 4.9±0.17µs +6.12%
Boolean Object Access (Full) 265.2±13.13µs 261.4±8.50µs +1.45%
Clean js (Execution) 783.2±54.33µs 724.2±38.29µs +8.15%
Clean js (Full) 1054.0±36.74µs 1024.6±41.47µs +2.87%
Clean js (Parser) 34.1±1.32µs 34.1±1.81µs 0.00%
Create Realm 492.3±41.15ns 460.4±25.50ns +6.93%
Dynamic Object Property Access (Execution) 5.8±0.46µs 5.4±0.23µs +7.41%
Dynamic Object Property Access (Full) 277.6±24.85µs 259.5±11.75µs +6.97%
Expression (Parser) 6.6±0.25µs 6.6±0.25µs 0.00%
Fibonacci (Execution) 818.8±24.10µs 800.3±34.36µs +2.31%
Fibonacci (Full) 1117.9±49.14µs 1059.9±69.05µs +5.47%
For loop (Execution) 22.1±0.74µs 22.3±0.92µs -0.90%
For loop (Full) 285.9±15.03µs 283.1±8.83µs +0.99%
For loop (Parser) 17.2±0.67µs 17.1±0.60µs +0.58%
Goal Symbols (Parser) 11.7±0.91µs 11.9±0.56µs -1.68%
Hello World (Parser) 2.9±0.11µs 2.8±0.12µs +3.57%
Long file (Parser) 757.1±22.08ns 767.6±30.72ns -1.37%
Mini js (Execution) 709.1±113.03µs 663.2±24.10µs +6.92%
Mini js (Full) 944.3±30.28µs 962.3±26.82µs -1.87%
Mini js (Parser) 30.3±1.25µs 30.3±1.39µs 0.00%
Number Object Access (Execution) 4.1±0.35µs 3.7±0.22µs +10.81%
Number Object Access (Full) 257.7±13.35µs 258.0±12.15µs -0.12%
Object Creation (Execution) 5.0±0.66µs 4.5±0.16µs +11.11%
Object Creation (Full) 346.3±33.32µs 308.6±11.18µs +12.22%
RegExp (Execution) 66.5±2.08µs 64.0±3.18µs +3.91%
RegExp (Full) 437.8±37.86µs 402.4±18.27µs +8.80%
RegExp Literal (Execution) 69.9±3.21µs 67.6±2.70µs +3.40%
RegExp Literal (Full) 347.3±43.46µs 331.6±11.96µs +4.73%
RegExp Literal Creation (Execution) 65.9±3.92µs 65.5±2.72µs +0.61%
RegExp Literal Creation (Full) 431.6±46.28µs 403.6±15.27µs +6.94%
Static Object Property Access (Execution) 5.1±0.43µs 4.8±0.15µs +6.25%
Static Object Property Access (Full) 272.2±22.98µs 257.2±8.58µs +5.83%
String Object Access (Execution) 7.6±1.44µs 6.9±0.34µs +10.14%
String Object Access (Full) 266.9±10.35µs 272.0±7.16µs -1.88%
String comparison (Execution) 6.5±0.50µs 6.1±0.25µs +6.56%
String comparison (Full) 264.8±8.72µs 260.1±10.34µs +1.81%
String concatenation (Execution) 5.1±0.18µs 5.0±0.41µs +2.00%
String concatenation (Full) 254.9±10.38µs 254.1±10.17µs +0.31%
String copy (Execution) 4.1±0.41µs 3.7±0.19µs +10.81%
String copy (Full) 250.4±11.45µs 252.7±9.85µs -0.91%
Symbols (Execution) 3.2±0.24µs 3.1±0.11µs +3.23%
Symbols (Full) 238.5±11.37µs 229.1±10.82µs +4.10%

@HalidOdat HalidOdat merged commit ad162e0 into master Sep 1, 2020
@HalidOdat HalidOdat deleted the feature/native-object branch September 1, 2020 14:02
@HalidOdat HalidOdat mentioned this pull request Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API deprecations Issues and PRs related to deprecations. enhancement New feature or request execution Issues or PRs related to code execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants