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

Peculiar performance with useWith #302

Open
bribes opened this issue Aug 26, 2024 · 3 comments
Open

Peculiar performance with useWith #302

bribes opened this issue Aug 26, 2024 · 3 comments

Comments

@bribes
Copy link
Contributor

bribes commented Aug 26, 2024

Is your feature request related to a problem? Please describe.
useWith is slower then just setting the it object to globalThis in the actual file.

Describe the solution you'd like
I am confused as to why, I used Object.entries(it).forEach(([key, value]) => globalThis[key] = value) in the template file and it was actually faster then using the useWith setting (in my testing)

Additional context
Will add tommorow, did some performance testing.

@nebrelbug
Copy link
Collaborator

That's fascinating! To be honest, I'm not surprised -- useWith has been recommended against for a while, so it's likely not optimized by most common JS runtimes.

@bribes
Copy link
Contributor Author

bribes commented Aug 26, 2024

Yeah seems like with() is always the slowest at first but gets faster overtime when it is run multiple times but is still slower then globalThis.
(This is not accurate):

with() 0.007s
globalThis 0.0004s

You can just set it up using functionHeader: 'Object.entries(Object.assign({},it)||{}).forEach(([k,v])=>globalThis[k]=v)' (Not using {...} spread as I believe it is slightly slower.
I could probably implement this directly but not sure if you want that. You should probably test it yourself.

@nebrelbug
Copy link
Collaborator

@bribes fascinating! I probably don't have time to test it right now, but it would be great if you wanted to add it to the documentation!

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

2 participants