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

vm.runInNewContext global variable access is significantly slower #37829

Closed
srolel opened this issue Mar 20, 2021 · 2 comments
Closed

vm.runInNewContext global variable access is significantly slower #37829

srolel opened this issue Mar 20, 2021 · 2 comments
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs.

Comments

@srolel
Copy link

srolel commented Mar 20, 2021

  • Version: 8.17.0, 9.11.2, 10.21.0, 11.15.0, 12.20.0, 13.14.0, 14.16.0, 15.12.0
  • Platform: 19.6.0 Darwin Kernel Version 19.6.0: Tue Jan 12 22:13:05 PST 2021; root:xnu-6153.141.16~1/RELEASE_X86_64 x86_64

What steps will reproduce the bug?

running:

const vm = require("vm");

const script = `
  (exports) => {
    exports.fn = () => {
      for (let i = 0; i < 10000; i++) {
        x;
      }
    };
  };
`;

global.x = 0;
eval(script)(exports);
console.time("eval");
exports.fn();
console.timeEnd("eval");

vm.runInNewContext(script, { x: 0 })(exports);
console.time("vm");
exports.fn();
console.timeEnd("vm");

results in:

eval: 0.251ms
vm: 1.124ms

How often does it reproduce? Is there a required condition?

consistently reproducible.

What is the expected behavior?

global variable access in new context should be approximately as fast as code running in global context.

What do you see instead?

global variable access in new context takes anywhere between 2x-10x more time than in global context.

@targos
Copy link
Member

targos commented Mar 20, 2021

I think it's a duplicate of #31658

@srolel
Copy link
Author

srolel commented Mar 20, 2021

ah, seems like it, thanks! thought I searched thoroughly...

@aduh95 aduh95 added the duplicate Issues and PRs that are duplicates of other issues or PRs. label Mar 20, 2021
@aduh95 aduh95 closed this as completed Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs.
Projects
None yet
Development

No branches or pull requests

3 participants