Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Why is this module so big? #617

Closed
joker-777 opened this issue Aug 7, 2018 · 10 comments
Closed

Why is this module so big? #617

joker-777 opened this issue Aug 7, 2018 · 10 comments
Labels
size Issues relating to the size of the library

Comments

@joker-777
Copy link

I juse react-instantsearch which includes this module. In the webpack analyzer I can see that algoliasearch-helper needs quite some space. Why?

algoliasearch_helper_graph

@Haroenv
Copy link
Contributor

Haroenv commented Aug 8, 2018

Hey @joker-777, this is something we are aware of, a big reason this is a big module is because it's using lodash. It's not quite straightforward to simply undo that usage because most methods we are using accept both arrays and objects, so it's a not insignificant amount of work. Secondly part of this is because of older parts of the API that are now handled by React InstantSearch (e.g. URL Sync) are in here, and can't be simply removed without a major version.

Unfortunately I don't have much more answer for you now, but we will work on this to make the module smaller in the future. If you're seeing obvious things that can shrink the code without too much work we can do those suggestions or merge those PRs before doing a significant effort too.

@Haroenv Haroenv added the size Issues relating to the size of the library label Aug 8, 2018
@joker-777
Copy link
Author

Thanks so much for answering. I'm happy that you are aware of it and are trying to reduce it in the future.
Do you already have a reduced version of lodash with only the methods you really need?

@Haroenv
Copy link
Contributor

Haroenv commented Aug 8, 2018

Yes, the version of lodash used is the subset of the methods we use (but it's still big because we use a lot of the methods).

There's definitely some things that can be improved on this on shorter term, but I haven't yet been able to fit it in my plans

@Haroenv
Copy link
Contributor

Haroenv commented Dec 21, 2018

Some sizes I have computed to see what is the biggest wins (everything I can think of is breaking change though, but stuff not used in our libraries)

Helper 35.3 kB
Helper - url 31.3 kB
Helper - url - SearchParameters 25 kB
Helper - url - SearchResults 24.8 kB
Helper - url - SearchParameters - SearchResults 17 kB
Helper - url - SearchParameters - SearchResults - events / util 12.7 kB
Helper - url - SearchParameters - SearchResults - AlgoliaSearchHelper 488 B

@staabm
Copy link

staabm commented Feb 12, 2019

Just want to also confirm, that InstantSearch javascript is way to big:

https://twitter.com/markusstaab/status/1094135682656808961

@Haroenv
Copy link
Contributor

Haroenv commented Feb 12, 2019

Thanks for crossposting here @staabm, the main reason is indeed here too. One way to already get a smaller size, is by using code splitting (using a build tool, and importing only the used parts of InstantSearch). Updating to InstantSearch v3 (you're on v1) also will save about 30% already.

@staabm
Copy link

staabm commented Feb 12, 2019

Updating to InstantSearch v3 (you're on v1) also will save about 30% already.

oh thats interessting. do I need to handle any BC breaks between v1 and v3, or can I just transparently update it?

Thank you!

@Haroenv
Copy link
Contributor

Haroenv commented Feb 12, 2019

There's a migration guide from v1 to v2 and from v2 to v3 here: https://www.algolia.com/doc/guides/building-search-ui/upgrade-guides/js/

There's definitely some breaking changes, but mostly naming changes and changed DOM to be more consistent

@Haroenv
Copy link
Contributor

Haroenv commented Mar 27, 2019

Recent quick experiment I did for changing the event emitter. util + events → mitt. It's not entirely straightforward; see developit/mitt#90. Maybe a different one has less changes to the node events package). The impact is 35.3 kB → 31.3 kB

@Haroenv
Copy link
Contributor

Haroenv commented Jul 11, 2019

This is fixed in v3 (yay finally!) You can already use the canary versions. I'll close this issue since our work on it is done, we went from:

97kb / 30kb gz

to

42kb / 10kb gz

https://bundlephobia.com/result?p=algoliasearch-helper@0.0.0-27095c0

Over time we hope to still decrease it by removing unneeded methods, but no major changes will happen further (ie we won't rewrite it fully)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
size Issues relating to the size of the library
Projects
None yet
Development

No branches or pull requests

3 participants