You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure if you're looking for opinions or suggestions from the community, but there are a few things I'd love to be discussed for a potential refactor for packaging.
Background
I'm part of the team that wrote the serverless-jetpack packaging plugin. The two main observations we'd had in analyzing a lot of serverless package-ing are:
Reading files from disk is super slow. (Serverless currently reads from disk to find devDependencies to exclude in node_modules via sync globby() calls and then reads files again for ** + service/function-level package.includes).
A lot of those files read from disk are then later excluded during the nanomatch() phase (where package.exclude is used and then package.include again).
The Jetpack plugin speeds things up in typical cases by:
Excluding all of node_modules
Using a much-faster, async little library (inspectdep) to infer only the production dependencies.
patching the include logic to basically insert prod dep patterns before package.include in the globby() and nanomatch() phases.
The Jetpack plugin is drop-in compatible and typically, much faster than built-in packaging, but even then we're finding that creating the fastest possible build is hitting limitations from maintaining compatibility with built-in serverless package that I'd love to see re-considered:
Suggestions
Remove the starting ** glob when doing the first phase globby() matching. While certainly easier for projects that want to include "everything" it ends up making things harder (moreso for Jetpack) that want to just cherry-pick specific stuff right from the start and especially mono-repos.
Jetpack has a harder case because we insert custom patterns before package.include for prod dependencies. After a lot of wrangling, we introduced a custom.jetpack.preInclude option that allows folks to insert stuff like: ** + custom.jetpack.preInclude + dynamic prod dependencies + built-in package.include to get the true flexibility we need.
Remove or refactor package.exclude to have it such that one (or even multiple) set(s) of patterns apply for the globby() phase and consider just removing the later nanomatch() phase entirely. Reading from disk is just so expensive, that I think we could just give a little more flexibility and education around packaging patterns to allow folks to craft a set of patterns that just include what you need (with positive and negative ones).
The motivation for putting these two things together is best illustrated in a private project I just helped with today: We recently had a project using Jetpack that had something simple like - exclude: ["**"] with lots of stuff brought back in via package.include -- this produced a package that excluded 17,000 files in the nanomatch() phase and took ~250 secs. Changing this to use the bespoke jetpack.custom.preInclude: ["!**"] (effectively starting with nothing in the globby()) phase) and not using package.exclude at all produced the same package with 0 files excluded in nanomatch() phase and taking only ~25 seconds.
... So that's a long-winded massive comment, but hopefully opens some points for consideration if the project is considering "all options" when approaching packaging. Keep up the great work and ❤️ all of the cool stuff that keeps coming out from the team!
Reacted by Daniel Schep
Reacted by Mariusz Nowak, Philipp Faster-Malkov, Sergii Kovalov, Ben Langlois, Jardel Weyrich and Kyle Joseph
@ryan-roemer great thanks for this write up! It's very valuable, and we'll definitely take all the points into account when refactoring our packaging logic.
I will close this issue, as it appears as duplicate (I was unaware) of #6580 and we handle all discussion and link all related issues over there
Activity
[-]Packagin - Refactor package plugin logic[/-][+]Packaging - Refactor package plugin logic[/+]ryan-roemer commentedon Aug 9, 2019
Hi folks!
Not sure if you're looking for opinions or suggestions from the community, but there are a few things I'd love to be discussed for a potential refactor for packaging.
Background
I'm part of the team that wrote the serverless-jetpack packaging plugin. The two main observations we'd had in analyzing a lot of
serverless package-ing are:devDependenciesto exclude innode_modulesvia syncglobby()calls and then reads files again for**+ service/function-levelpackage.includes).nanomatch()phase (wherepackage.excludeis used and thenpackage.includeagain).The Jetpack plugin speeds things up in typical cases by:
node_modulesinspectdep) to infer only the production dependencies.includelogic to basically insert prod dep patterns beforepackage.includein theglobby()andnanomatch()phases.The Jetpack plugin is drop-in compatible and typically, much faster than built-in packaging, but even then we're finding that creating the fastest possible build is hitting limitations from maintaining compatibility with built-in
serverless packagethat I'd love to see re-considered:Suggestions
**glob when doing the first phaseglobby()matching. While certainly easier for projects that want to include "everything" it ends up making things harder (moreso for Jetpack) that want to just cherry-pick specific stuff right from the start and especially mono-repos.package.includefor prod dependencies. After a lot of wrangling, we introduced acustom.jetpack.preIncludeoption that allows folks to insert stuff like:**+custom.jetpack.preInclude+ dynamic prod dependencies + built-inpackage.includeto get the true flexibility we need.package.excludeto have it such that one (or even multiple) set(s) of patterns apply for theglobby()phase and consider just removing the laternanomatch()phase entirely. Reading from disk is just so expensive, that I think we could just give a little more flexibility and education around packaging patterns to allow folks to craft a set of patterns that just include what you need (with positive and negative ones).The motivation for putting these two things together is best illustrated in a private project I just helped with today: We recently had a project using Jetpack that had something simple like
- exclude: ["**"]with lots of stuff brought back in viapackage.include-- this produced a package that excluded 17,000 files in thenanomatch()phase and took ~250 secs. Changing this to use the bespokejetpack.custom.preInclude: ["!**"](effectively starting with nothing in theglobby()) phase) and not usingpackage.excludeat all produced the same package with 0 files excluded innanomatch()phase and taking only ~25 seconds.... So that's a long-winded massive comment, but hopefully opens some points for consideration if the project is considering "all options" when approaching packaging. Keep up the great work and ❤️ all of the cool stuff that keeps coming out from the team!
medikoo commentedon Apr 27, 2020
@ryan-roemer great thanks for this write up! It's very valuable, and we'll definitely take all the points into account when refactoring our packaging logic.
I will close this issue, as it appears as duplicate (I was unaware) of #6580 and we handle all discussion and link all related issues over there