-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Investigate core.js performance impacts on VU initialization and memory usage #1036
Comments
quick and dirty would be to init it once in js/lib/lib.go:
and set it in js/lib/rice-box.go at the end:
if i do not understand something wrong |
Edit: disregard, totally misread the comment above 🤦♂️
|
i'm a bit confused, what i was pointing out is just a simple go solution which compiles the program only once and returns only, if requested, the pointer to that program. so you would get the same pointer no matter how often you call the GetCoreJS func. |
Ah, sorry, totally disregard my previous message, my sleep-addled brain completely misread half of your proposal... |
After second (more caffeinated) look at your proposal, you are absolutely right! I never noticed that we're parsing core.js anew for every VU 🤦♂️ Sorry again for my previous stupid response... 😊 I'll submit a PR with a fix shortly, though I'll probably use |
sounds good. the proposal with the flag for babel seems also nice ;) |
i guess this can be closed now, or do you wait until the next release? btw, are you planning to do one in the near future? |
Prompted by this StackOverflow question, I briefly investigated why VUs take so much memory. I found out that the major culprit for the memory usage (of simple scripts) is the core.js library we include in every VU. We need it as a polyfil, because goja doesn't implement big chunks of the ECMAScript 6+ specs, but if I remove these three lines: https://github.com/loadimpact/k6/blob/2999a1e8e6657d88853f8d65fe195226173645e2/js/bundle.go#L246-L248
And run a simple script with 2000 VUs, on my machine k6 initializes those 2000 VUs in under 2 seconds and takes just under 300 MB of RAM, instead of the ~10000MB mentioned in the StackOverflow question (that I also confirmed locally with k6 0.24.0).
Something that might help with this memory usage is for us to avoid importing the whole core.js library, maybe something like this: https://babeljs.io/docs/en/babel-preset-env#usebuiltins-usage-experimental
Or, have a CLI flag/environment variable that tells k6 "I am a JS professional, I know what I'm doing". Basically, a mode that disables any babel and core.js work from k6 and relies that the user has passed their script through whatever babel/browserify/webpack/rollup/core.js/typescript/some-new-js-thing conversion process they desire and passes the ES5.1-compliant result to k6 for execution.
The text was updated successfully, but these errors were encountered: