-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Investigate swapping Underscore w/ Lo-Dash or upgrading Underscore #1009
Comments
Any updates on this? |
Any update. I need some of LoDash's methods, including _.cloneDeep() |
In Meteor, you probably want EJSON.clone. Lodash continues to be something I/we are curious about but never seems to |
Thanks very much, David. I wasn't aware of EJSON.clone. |
Thanks for the interest in lodash. Let me know if you all revisit the issue in the future. |
Hi, JDalton, I am confident the Meteor Devs (also known as MDG, for Meteor Developer Group) will no doubt add LoDash to Meteor. But they started with Underscore as the safe bet at the time, I suppose. On top of that, I think they like to do their due diligence to make sure any package they add to the core Meteor platform is sufficiently tested and reliably integrated. Therefore, I think they really just need a little push and the the time to include LoDash, but they wouldn't act unless there is enough interest. And based on the activity on this Github issue, there is not enough interest to rise to "sufficient." LoDash is amazing and incredibly useful, btw. I have been using it with Backbone and Ember. And now that I am using Meteor, I expect to continue to use it. Thanks for your work on LoDash. |
Lodash looks great. But just like every time we upgrade a Node minor Minor underscore version bumps have caused regressions for Meteor. Swapping |
+1 |
+1 Doing some benchmarks and profiling most time in our application is spent on underscore (and minimongo). So I am sure performance of many applications could be improved by switching. See the lodash website for in-depth benchmarks. |
+1 |
5 similar comments
👍 |
+1 |
+1 |
👍 |
+1 |
+1 On Sun, Mar 16, 2014 at 5:15 PM, Fabian Vogelsteller <
|
+1 |
2 similar comments
+1 |
+1 |
+1 I find lodash a great replacement for underscore, and use it whenever I can. I'm having problems fitting it into Meteor though, due to that integrating underscore already :( |
+1 |
Voting for this too. Lodash is better and more reliable. |
I want Lodash too please! |
+1 |
1 similar comment
+1 |
By the way. You can use Lodash instead of Underscore for your own code without problems. Just remove the dependency on standard-app-package and depend on the listed packages instead (select the release version you use). Make sure to remove underscore from your package.js. Then you can use the Lodash atmosphere package with I hope that helps some people, because I myself realised it quite late that there is no namespace conflict with |
Despite the huge number of people saying vaguely that lodash is "faster" than Underscore over the years on this thread and pointing to various benchmarks, there haven't been too many concrete points about what that means. Here's something I learned today on an old Meteor project that uses Underscore instead of Lodash: Lodash provides linear-time algorithms for large arrays passed to functions like _.difference, _.uniq, and _.union, where Underscore only provides quadratic algorithms for these functions. Using _.union in this particular project has apparently been leading directly to outages. Had I understood that back when I was personally one of the active maintainers of the Meteor framework, I think that would have been much more motivating than the hundreds of low-information "+1", "it's better", and "it's faster" comments here. Unfortunately, I don't personally have the time to work on this change now, but I suppose add me to the chorus of upvotes at last :) |
Maybe the easiest thing would be to swap underscore with lodash in one release candidate, allow developers to run their projects with it, and report if anything breaks. |
My solution using lodash with Meteor ES2015:
and import lodash
Regards, Nicholls |
@jdnichollsc we are talking about using lodash in the Meteor core packages including those on the server side. |
I once tried the underscore to lodash refactor, just to get a sense of the scope of the problem. It's a gnarly refactor. The API for underscore is large, and used extensively throughout the Meteor codebase. As I recall, there were thousands of broken reference the first pass through; which were actually fairly straight forward to clean up; but once the references were cleaned up, there were hundreds of broken calls; related to dozens of mangled files. It was layers and layers of refactoring. The best way to do the refactor, in my opinion, is to divide it into parts, and be slow and consistent. @jdnichollsc is probably right. The best bet is to bring both lodash and underscore into the codebase, and rewrite one package at a time. Separating the packages out into independent NPM packages is probably a good stepping-stone. If a package can be installed independently via NPM, it's probably decoupled enough that it's underscore references can be cleanly replaced with lodash. |
I wonder if TypeScript or Flow could be helpful in using a computer to identify places where the API is different. |
API differences are documented in the Migrating page.
As I recall, this was the second or third step in the process; and where I hit a wall (in part, because I didn't have the above documentation). The first step was to replace the Underscore references with Lodash. That breaks the builder, because it can't load up all the files. Once all the references are updated, then Meteor will start going through the build pipeline. Unfortunately, the build pipeline involves things like I'm handwaving a bit, since it's been at least a year since I tried that refactor, and I don't recall all the details. But it's a metric ton of errors. |
I wonder what the impact on user apps would be of a change like this. I suppose as long as we provide a shim to use underscore for parts of the app during a transition period it could be fine, but if it's this hard for the Meteor code base it could be even harder for apps. |
BTW, this is the most upvoted issue for Meteor. |
Just as a reminder: You can and have been able to use I'm here to instill hope that this has not been forgotten and is in the works! Getting a bit more detailed: For those interested in how Underscore weighs in within the Meteor code, I'll point you to the Underscore tally counts I generated in researching this project a couple weeks ago:
As has been stated throughout this issue, especially by those who have made the attempt to undertake this project (very much appreciated, to those who have tried!), there are a number of obstacles: very old While one option for this was to openly and willingly accept PRs for this transition and given the vast scope of Underscore in Meteor and the large potential for manual error in making the (sometimes complicated) changes, or even reviewing the changes, I'm currently pressing forward with an automated process to avoid both the time-sink the high margin-of-error. I am (currently) in the process of writing AST transformations which will programmatically (using I'm aware of existing codemods which attempt to make this transformation automatically, but in trying those, I've certainly ran into many bumps, some of which are unique to the Meteor core (though rest assure, I'm taking solace and inspiration from their existence). We also have considerations of making sure we play nicely with those who want to keep using I'm hope that some of the tooling I'm building will be helpful to others too (even if this migration might be less common now than in the past) and I hope to share more info soon! |
In my opinion, while swapping underscore with lodash is a waste of time, swapping underscore with native functions is a plus. https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore In propably less than 2 years somebody will open an issue with the title: "Investigate swapping lodash with xyz"? |
@pozylon You might check out this post. Lodash is a collection of ~300 modules, considerably more than the handful of ES5/6/7 methods, and offers features beyond those of their built-in counterparts. Lodash works great combined with ES6 and there's even a lodash-es package. You might also dig that Lodash v5 is being written in ES6/7 too. Unlike Underscore, which has been dormant for ~2yrs, Lodash has evolved with the language and ecosystem. This is also why Lodash continues to gain users with over 1,000 new package dependents each month for the last 2 years, more than 30,000 packages directly depending on it, and more than 110,000 packages (30% of npm) impacted by it in some way. |
@abernix How will it be packaged? As a meteor package, an npm dependency in the package.js or just as peer dependency so users can use their own version (within limits)? It'd be interesting to have separate counts for files that are server-only and files that are included in the client bundle. I think one of the major concerns is bundle size. Although this could be alleviated by only requiring the necessary lodash modules, at least until there is support for tree-shaking. |
@jdalton I truly appreciate what you have done for the whole js community and I use lodash myself. Still I think getting rid of dependencies is preferrable over replacing dependencies if +/- same amount of time has to be invested. Lodash is more popular than ever and exxtremely well maintained but underscore too had some fans before the 2y rapunzel sleep... |
Lodash is modular, so folks can use as little or as much as they'd like. It makes sense to use something that's battle tested rather than reinventing the wheel of fundamentals.
Judging by how long this issue has existed maybe Lodash's future is the least of the worries here. I understand your concern, but I think it's a bit premature/unwarranted (has the slight ring of NIH). Update: |
@sebakerckhof That's a great question! I've gone through a couple iterations/preliminary attempts at figuring the best solution for this. While a peer-NPM dependency implementation might be one way to avoid duplication and bundle bloat, the current implementation of Meteor's NPM peer dependency system wouldn't trickle up as far as the Meteor server bundle itself – a place where a lot of current Currently, I'm creating a The current Internally, the The responsibility of the developers of Meteor apps (and packages) will then be to import methodName from 'meteor/lodash/methodName'; or import _ from 'meteor/lodash/core'; In a similar way as to how Also, since Meteor 1.5 will support dynamic imports, you could benefit further in some cases if you loaded more beefy import("meteor/lodash/debounce").then(debounce => {
// Some debounce-y fun, if that's even possible.
debounce(fun, 2000);
}); In a future reality, where Meteor moves more toward full NPM integration, a peer NPM dependency setup will be the natural course for this (as with the rest of Meteor packages). This might seem like a counter-measure to that right now, but I can assure you that this transition does not need to be any more complicated than it is already (nor wait and take any longer). Additionally, in the future, developers will only have to remove the @pozylon Somewhere out there, some day, maybe a version of ECMAScript exists that might maybe natively provide all of the features that |
Yep, seems like a clean way forward. |
You'll have more tree-shaking and optimization opportunities going the |
I did move in the direction of using We won't need this stubbed-pattern long-term, but I'd like to easily generate new versions of the Meteor |
@abernix Using the mapping of |
To help provide a more clear separation between feature requests and bugs, and to help clean up the feature request backlog, Meteor feature requests are now being managed under the https://github.com/meteor/meteor-feature-requests repository. Migrated to meteor/meteor-feature-requests#48. |
Just as an update on the status of this (important) task before the updates move over to the feature request repository... I did complete the work to replace I'm aware of the reasons and I will develop a plan soon to resolve that and get this released. This will be even easier with the |
_86 Upvotes_ It's been mentioned a few times, so I figured I'd track progress/questions with an issue.
_85 Upvotes_
The text was updated successfully, but these errors were encountered: