Peculiar performance with useWith
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.
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.
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.
@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!
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.0004sYou 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.
Don't do your "recommended solution" (and it should not be mentionned in the documentation) as it will lead to race conditions.
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.0004sYou 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.Don't do your "recommended solution" (and it should not be mentionned in the documentation) as it will lead to race conditions.
Oh damn I didn't realize this, I probably won't have time to make a pull request to remove from documentation anytime soon, could you do it? I can do it whenever I have time though.
I just updated the docs to remove that suggestion. @bribes thanks for the heads up.