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
Consider faster alternatives to lodash/isPlainObject #2214
Comments
It's also worth noting that even with the performance boost we get from swapping out We are pre-v1.0.0 but explicitly opted-in to data deep merge. I believe that it's on by default for everyone post-v1.0.0, so maybe it's worth taking a pass at optimizing the merge algorithm? I could imagine other sites that didn't have data deep merge turned on seeing a slowdown in v1.0.0 if they suddenly start hitting this code path. |
One more data point—I did some basic logging and found that for our ~3300 page site, Line 4 in 08fe54e
isPlainObject() , ends up having a significant impact on our builds.
|
88 million times! 🤯 |
…Object for performance reasons. See #2214.
Whew, alright! A few things here! (and a celebration of this as the first issue post-Netlify sponsorship 🥳) I opened #2219 in service of this! Very happy to entertain reviews over there! I looked at a few different implementations here and took inspiration from Test suites are passing fine on our end. I would note that, in the larger picture, this likely isn’t strictly limited to deep data merge, it’s used heavily in Found in:
Couple of things I would love to see here:
|
Performance comparisonWe've been slow to move to v1.0.0, so doing a direct comparison requires hacking at our dependencies a little bit. If I manually switch to update to the tagged v1.0.0 release, and run $ npm run eleventy
> web.dev@3.0.0 eleventy /Users/.../git/web.dev
> eleventy --quiet
Eleventy is building, please wait…
[11ty] Wrote 3378 files in 45.67 seconds (13.5ms each, v1.0.0) If I switch to your branch locally and run things again, I see: $ npm run eleventy
> web.dev@3.0.0 eleventy /Users/.../git/web.dev
> eleventy --quiet
Eleventy is building, please wait…
[11ty] Wrote 3378 files in 32.70 seconds (9.7ms each, v1.0.1-canary.2) So, definitely better! 💥 Trying this yourselfIf you want to try it yourself, you shouldn't have to do much more than clone https://github.com/GoogleChrome/web.dev, hack the We're currently using node v14 throughout the project, and the overall build times (irrespective of this patch) get better when using node v16. So that's something on our end we're looking to upgrade. Other codepathsI specifically saw I actually am looking after this codebase on a short-term basis, and am not 100% sure what our Computed Data and Further Merge improvementsI had done a bit of code golf to see if some calls to |
Excellent, thank you @jeffposnick! I think we can maybe consider this one resolved for now? I might file another issue to do more performance investigation on web.dev. Looking at a bigger picture, I’d love to get a test corpus of large open source projects to performance test releases on, but I don’t know if that makes sense to do with how tied some of these codebases can be to individual versions. I do have https://github.com/11ty/eleventy-benchmark in place for some very rudimentary “lots of files” testing, but the test projects there are very uniform. If I might recommend further investigation, I’d suggest looking for |
@zachleat my own website builds a lot of files (a little less than web.dev):
(Whoops, this one is not yet on v1… 😅) So if you have instructions on how and where to do performance tests, I can try. |
Is your feature request related to a problem? Please describe.
I'm taking a look at the build performance of https://github.com/GoogleChrome/web.dev, which is a fairly large (~3300 files) 11ty site.
Describe the solution you'd like
A detailed description of one of my initial findings is at GoogleChrome/web.dev#7339; the takeaway is that
eleventy/src/Util/Merge.js
Line 1 in 08fe54e
module-alias
to swap outlodash/isPlainObject
for the implementation fromtypechecker
, without making any other changes, takes our build time down from 55 seconds to 40 seconds.It would be great if someone from the core 11ty team could try making this change as well and see if they experience similar performance improvements on large sites, without any unintended changes. I'm assuming the 11ty test suite would pick up any compatibility issues.
Describe alternatives you've considered
I can't guarantee whether the implementation in
typechecker
is 100% compatible withlodash/isPlainObject
, or whethertypechecker
's implementation is faster than a few other implementations that I found onnpm
.Additional context
As mentioned, there are details in GoogleChrome/web.dev#7339 of the methodology for this investigation and steps to reproduce what I tried.
The text was updated successfully, but these errors were encountered: