Fast path for CommonJS on Module._compile
Nobody has claimed this yet.
- Dominant language
- Shell
- Stars
- 399
- Forks
- 11
- Avg merge
- 29m
- Merged PRs (30d)
- 1
Description
In theory, we can move the load of content of a module to C++ when:
- the experimental policy is not enabled
- and when the module is not ESM
- and when the module is not patched
Since the content goes directly to the C++ without modification:
- https://github.com/nodejs/node/blob/main/lib/internal/modules/cjs/loader.js#L1288
- https://github.com/nodejs/node/blob/main/lib/internal/vm.js#L78
- https://github.com/nodejs/node/blob/95b198911382b0aa0a0448e2a86214558665e02b/src/node_contextify.cc#L975
Also, I don't have any idea if worth or is viable but maybe we could use StreamedSource instead of Source, in this way, we probably can save some memory and load the script much faster.
Let me know what you think, this is something that was in my mind for a while and I just wanna to share it with more people to understand if is possible or not.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib/internal/modules/cjs/loader.js at the referenced content-loading and Module._compile paths, then follow lib/internal/vm.js and src/node_contextify.cc. Review the V8 StreamedSource reference to determine whether either optimization is viable. Done would require an agreed scope, implementation measurements, and evidence of improved loading or memory use.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, javascript, node.js
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100