-
Notifications
You must be signed in to change notification settings - Fork 5.7k
feat: drastically improved dev dependency exclusion performance #5574
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
Conversation
|
Awesome @MacMcIrish! Thanks for the PR. Do you have a good |
|
@dschep of course :) I've just made a couple more changes to the PR after investigating |
|
@dschep I've got a snippet here to reproduce, using #!/bin/sh
rm -rf testProject
sls create --template aws-nodejs --path testProject
(cd testProject \
&& echo 'yarn-offline-mirror "./offline/package"' > .yarnrc \
&& yarn add [email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
&& yarn add --dev @babel/[email protected] \
@babel/[email protected] \
@babel/[email protected] \
@babel/[email protected] \
@babel/[email protected] \
@babel/[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
micromatch@^3.1.10 \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
&& echo -e 'package:\n exclude:\n - offline/**' >> serverless.yml \
&& time sls package)Outputs: Whereas using my branch outputs: |
|
We would love to see this merged in and released quickly as it really hinders our ability to deploy quickly and clogging up ci. Cheers! |
|
Thanks for the snippet @MacMcIrish. I'll test it tomorrow. We'll release this soon @simlu |
dschep
left a comment
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.
Looks & works great @MacMcIrish! It doesn't seem we have much test coverage of resolveFilePathsFromPatterns. Would you mind adding some? It's probably best to use os.tmpdir() and set this.serverless.config.servicePath to the created temp dir then fill it with some empty files&dirs. I'm happy to do it, but it might take longer 😉
| const path = require('path'); | ||
| const globby = require('globby'); | ||
| const _ = require('lodash'); | ||
| const nanomatch = require('nanomatch'); |
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.
Wow. @micromatch publishes micromatch, nanomatch picomatch, and anymatch. That's not confusing at all 🙄
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.
We had our fun with glob and *match yesterday :) Globby uses fast glob. Fast glob only uses default wildcard pattern according to their docs. However internally they use micromatch, not nanomatch. So they might actually expose the extended syntax that it provides over nanomatch.
We could start using micromatch instead of nanomatch here. I have to check what fast glob does internally. Maybe that's a test we could be adding. This whole thing is so confusing haha... Would have loved to fix it downstream, but honestly don't have the time right now and this is pressing.
Somewhat unrelated but interesting:
- Globby seems so calls fast glob for each pattern which results in many file scans. Who wrote that and thought it was performant?! All we did is replicate that functionality in memory.
- Still not entirely sure what the difference between picomatch and nanomatch really is. No dependencies for picomatch?
- We also have npm glob which provides its own custom syntax and uses minimatch (which is apparently slow).
|
@dschep There is honestly a lot of test coverage already testing this (test were testing globby functionality, now testing our code), which is why we didn't add more tests. I'm confused what else you want tested here? Are you just asking because we didn't add tests in this pr? |
|
Oh, I failed to find them then @simlu, I expected them in |
|
@dschep There are a few integration tests that check this in Please let me know if that is sufficient :) |
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.
Yup. That's more than enough. I should've looked harder.
probably gonna
sometime next week
|
Awesome, cheers! |
|
I'm running an up to date sls version 1.39.1 with node v8.10.0 and Python 3.7.2 and am finding that trivially small Python package builds (e.g. 50KB) are taking 5+ minutes. A debug run of sls suggests that it's the 'Excluding development dependencies...' step that's taking most of the time. How can I verify that I have this fix? If 1.39.1 has the fix, what else could cause this delay? Thanks. |
|
Same here |
|
Even using the latest version (by running $ sls -v
Framework Core: 2.16.1 (local)
Plugin: 4.3.0
SDK: 2.3.2
Components: 3.4.3it still takes well over a minute to go through the This has worked for me and reduced the packaging time to less than a second: package:
excludeDevDependencies: false
exclude:
- ./**
- '!package.json'
- '!src/**'
- '!node_modules/<npm-mod-1>/**'
- '!node_modules/<npm-mod-n>/**'Hopefully it will help others as a workaround! |
What did you implement:
Closes #5568
How did you implement it:
Instead of passing the complete pattern list into Globby, a complete project file list is loaded into memory and then resolved from the patterns using
micromatch. The use ofmicromatchhere is becauseglobitself usesminimatch, which is why we're seeing such a significant performance difference.How can we verify it:
Run
sls packageon a project with a large file count with many dev dependencies. The difference in timing is ~30s compared to ~15 minutes.Todos:
Is this ready for review?: YES
Is it a breaking change?: NO