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

Jarvis Emitter Interface Builder - Can be faster! #2

Open
KromDaniel opened this issue Feb 13, 2019 · 0 comments
Open

Jarvis Emitter Interface Builder - Can be faster! #2

KromDaniel opened this issue Feb 13, 2019 · 0 comments

Comments

@KromDaniel
Copy link

Hey
This is micro optimisation, but still

If I'll take the following loop:

console.time('creating a lot of');
// we push to array else v8 can skip the entire loop
const jarvises = [];
for(let i=0; i < 2**24; i++) {
    jarvises.push(
        new JarvisEmitterInterfaceBuilder()
        .name('dynamicName')
        .role('someRole')
        .sticky(false)
        .description('my Description')
        .build(),
    );
}
console.timeEnd('creating a lot of');

And run it, it takes around ~4200MS

Let's have a look at the constructor:

class JarvisEmitterInterfaceBuilder {
	constructor() {
		this.object = {};
	}

and It will dynamically create the keys name, role etc (v8 unlikes it)

But if I'll pre-create them (v8 likes it)

class JarvisEmitterInterfaceBuilder {
	constructor() {
		this.object = {
                   name: null,
                   role: null,
                   sticky: null,
                   description: null,
           };
	}

And run the same loop again, it will take ~1900MS around 2.2x times faster

The only question is, can these fields be nullable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant