Skip to content
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

Go on a Diet #2060

Open
jashkenas opened this issue Feb 19, 2015 · 8 comments
Open

Go on a Diet #2060

jashkenas opened this issue Feb 19, 2015 · 8 comments

Comments

@jashkenas
Copy link
Owner

Underscore is getting a little chunky around the edges...

We're up to 5.8k, minified and gzipped. It would be lovely to get that back down under 5...

@megawac
Copy link
Collaborator

megawac commented Feb 20, 2015

Theres better ways to do this than deleting methods. omit and pick, max and min and several others are nearly duplicates of each other. It would not be hard to generate those functions

@paulfalgout
Copy link
Contributor

Maybe if we dropped support for older browsers we could cut down on the size..

Oh didn't see this one:

@jamiebuilds
Copy link
Contributor

I'd be happy to spend a few hours looking for places to trim down (I'm sure others would too). However, no one was given the opportunity.

I know what the answer is going to be to this, but please mark 1.7 as latest on npm and revert 1.8 before people start using it.

@megawac
Copy link
Collaborator

megawac commented Mar 21, 2015

Also ping #1594

@jmdevivo
Copy link

Could we look for some features in underscore that could be moved to underscore-contrib?

@jdalton
Copy link
Contributor

jdalton commented Aug 4, 2015

FYI Underscore is now 6kb gzipped, which is up from 5.8kb for v1.8.3 (site says 5.7kb).

@dperrymorrow
Copy link

Im sure there is an excellent reason for this, and id love to hear it but wouldn't it save quite a bit of size if Underscore used more of its own functions internally? such as _.each, _.filter, _.map ect...

At quick glance it seems there a quite a few more places that Underscore could "Dog Food" itself.

One of the things I love about Underscore is how it decreases the amount of Javascript I write in my projects. Seems Underscore itself could take more advantage of that.

@jdalton
Copy link
Contributor

jdalton commented Dec 1, 2015

@dperrymorrow

Im sure there is an excellent reason for this, and id love to hear it but wouldn't it save quite a bit of size if Underscore used more of its own functions internally? such as _.each, _.filter, _.map ect...

My guess is it's a concern over performance. That said I'm sure there are plenty of methods where performance isn't a concern for their common usage scenarios. It would be worth reviewing areas where dog fooding can be improved, nixing those areas where perf flags are raised.

captbaritone added a commit to captbaritone/underscore that referenced this issue Dec 10, 2015
These two functions were nearly identical. Inspired by jashkenas#2060, I thought I would
try to combine the two to save some bytes. Ironically, repetitive code gzips
very well, so this refactor actually ends up _adding_ 3 bytes to the
minified-gzipped size. Oh well.

Never the less, I figured I'd open the PR, since it does reduce repetition in
the source code, and maybe it will serve as a guide for somebody else who looks
into combing these.

Pros:

* Less code in underscore.js
* DRYer code (https://en.wikipedia.org/wiki/Don't_repeat_yourself)

Cons:

* Larger gzipped file size
* Possibly a _tiny_ bit slower (I'm no perf expert)
* Code is harder to understand
captbaritone added a commit to captbaritone/underscore that referenced this issue Dec 10, 2015
These two functions were nearly identical. Inspired by jashkenas#2060, I thought I would
try to combine the two to save some bytes. Ironically, repetitive code gzips
very well, so this refactor actually ends up _adding_ 3 bytes to the
minified-gzipped size. Oh well.

Never the less, I figured I'd open the PR, since it does reduce repetition in
the source code, and maybe it will serve as a guide for somebody else who looks
into combing these.

Pros:

* Less code in underscore.js
* DRYer code (https://en.wikipedia.org/wiki/Don't_repeat_yourself)

Cons:

* Larger gzipped file size
* Possibly a _tiny_ bit slower (I'm no perf expert)
* Code is harder to understand
captbaritone added a commit to captbaritone/underscore that referenced this issue Dec 10, 2015
These two functions were nearly identical. Inspired by jashkenas#2060, I thought I would
try to combine the two to save some bytes. Ironically, repetitive code gzips
very well, so this refactor actually ends up _adding_ 3 bytes to the
minified-gzipped size. Oh well.

Never the less, I figured I'd open the PR, since it does reduce repetition in
the source code, and maybe it will serve as a guide for somebody else who looks
into combing these.

Pros:

* Less code in underscore.js
* DRYer code (https://en.wikipedia.org/wiki/Don't_repeat_yourself)

Cons:

* Larger gzipped file size
* Possibly a _tiny_ bit slower (I'm no perf expert)
* Code is harder to understand
captbaritone added a commit to captbaritone/underscore that referenced this issue Dec 10, 2015
These two functions were nearly identical. Inspired by jashkenas#2060, I thought I would
try to combine the two to save some bytes. Ironically, repetitive code gzips
very well, so this refactor actually ends up _adding_ 3 bytes to the
minified-gzipped size. Oh well.

Never the less, I figured I'd open the PR, since it does reduce repetition in
the source code, and maybe it will serve as a guide for somebody else who looks
into combing these.

Pros:

* Less code in underscore.js
* DRYer code (https://en.wikipedia.org/wiki/Don't_repeat_yourself)

Cons:

* Larger gzipped file size
* Possibly a _tiny_ bit slower (I'm no perf expert)
* Code is harder to understand
captbaritone added a commit to captbaritone/underscore that referenced this issue Mar 24, 2016
Saves 4 bytes gzipped, and I don't find it any harder to read.

One minuscule step toward jashkenas#2060
captbaritone added a commit to captbaritone/underscore that referenced this issue Mar 25, 2016
The way a code change maps to a change in minified/gzipped size is not always
intuitive (jashkenas#2383). To help folks in our effort to slim down (jashkenas#2060), they can
now issue the command:

    npm run weight

And get output like:

    6.27 kB

Which should give a fairly good estimate of the "over-the-wire" size of their
`underscore.js`.

Caveat: The weight reported does not include the source-map comment at the end
of the file.
@jgonggrijp jgonggrijp mentioned this issue Feb 7, 2021
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants