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

Consider limiting the number of AsyncContext variables allocated #50

Open
littledan opened this issue Apr 21, 2023 · 3 comments
Open

Consider limiting the number of AsyncContext variables allocated #50

littledan opened this issue Apr 21, 2023 · 3 comments

Comments

@littledan
Copy link
Member

@syg expressed the concern at TC39 that JS developers may allocate too many AsyncContext variables, slowing down their programs and creating unmanageable expectations on JS engines to make it fast somehow. In general, I think the best practice is for each library or framework to create just one AsyncContext variable. But could we actually enforce a limit on the total number of variables created?

In general, in JS, the specification does not indicate hard limits for real resources like the heap size or the callstack size--it's just implicit that the JS engine may throw an exception or terminate if unspecified limits are exceeded. On the other hand, WebAssembly has standardized its implementation-defined limits at https://webassembly.github.io/spec/js-api/#limits . I wonder if, in JS, we could agree on implementation-defined limits for certain aspects of certain new features, like this.

What if we had an overall limit of AsyncContext variables, after which an exception is thrown if JS tries to allocate more? Maybe this could be 1000 or 10000--I really can't imagine valid use case requiring more than that.

@quisido
Copy link

quisido commented Apr 6, 2024

But why?

An unrestricted tool allows you to build a restrictive wrapper around it, but a restricted tool only fails its users who have edge cases.

If you only want 1000 -- or even 1 -- variable, you are able to self-impose these restrictions in your own applications.

@littledan
Copy link
Member Author

Yeah, I think if we come up with a good data structure for the AsyncContext.Snapshot representation (as investigated in this design doc), there shouldn't really be a need to limit the number of AsyncContext.Variable instances allocated. But we might want to leave this issue open to be resolved during Stage 3, to track any issues which may come up.

@jasnell
Copy link

jasnell commented Apr 8, 2024

I'd be strongly -1 on trying to place limits on the number of AsyncContext.Variable instances created.

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

3 participants