-
Notifications
You must be signed in to change notification settings - Fork 35
feat: improve performance by reworking caching and supply cache to NFT #1244
Conversation
⏱ Benchmark resultslargeDepsEsbuild: 2.1s
Legend
largeDepsNft: 9.4s
Legend
largeDepsZisi: 14.5s
Legend
|
// loses part of the return type information. We can safely say it's a | ||
// Buffer in this case because we're not specifying an encoding. | ||
const binaryInfo = detect(buffer as Buffer) | ||
const fileContents = await readFile(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the cache here, as this is reading a binary file and we only do that once for a binary we find in the function folder.
|
||
import { isNativeModule } from '../../utils/detect_native_module.js' | ||
import { PackageJson } from '../../utils/package_json.js' | ||
import { PackageJson, readPackageJson } from '../../utils/package_json.js' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
read-package-json-fast
does JSON.parse(readFile())
plus some additional validation and checks for binary folders. So our implementation should actually be faster without those checks. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the idea of having a single cache entity that is used for IO operations and for NFT! ✨
I left a few comments, but looks great in general.
Co-authored-by: Eduardo Bouças <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! This change is significant enough to warrant a feature flag, but I'm not sure how easy it would be to add one, since the changes have pretty deep ramifications.
Have you thought about that?
Yes I forgot about this. I put the nft cache and the higher file IO limit behind FF. The rest was more or less a refactor and should not change much. |
netlify/zip-it-and-ship-it#1244) * feat: improve performance by reworking caching and supply cache to NFT * chore: move cache into class * chore: comment about fileIOConcurrency * Update src/runtimes/node/bundlers/nft/es_modules.ts Co-authored-by: Eduardo Bouças <[email protected]> * chore: fix comment * chore: fix comment * chore: add ff Co-authored-by: Eduardo Bouças <[email protected]>
Summary
Based on #1243
Ref: https://github.com/netlify/pod-compute/issues/252
There is also another PR that I created in NFT, as NFT does not correctly cache, which will bring another small performance boost. vercel/nft#320
For us to review and ship your PR efficiently, please perform the following steps:
This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing
a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
passes our tests.
A picture of a cute animal (not mandatory, but encouraged)