-
Notifications
You must be signed in to change notification settings - Fork 16
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
Refactor to work with Tree Shaking #475
Comments
If it's really important to reduce bundle size right now before undertaking such an ambitious refactor, we could do a minor refactor and move |
I use If I do that, I could probably fix this much more simply by making Either way (even if do the full split/refactor), I would also need to refactor hebcal/hebcal-leyning to remove all references to Tree shaking should then automatically remove the large dependencies (the entire I don't think this is particularly urgent for me right now, but I did start working on it. |
Looping over all dates is pretty easy. You'll find this idiom in a few places: const startAbs = HDate.hebrew2abs(year, TISHREI, 1);
const endAbs = HDate.hebrew2abs(year + 1, TISHREI, 1) - 1;
for (let absDt = startAbs; absDt <= endAbs; absDt++) {
const events = HebrewCalendar.getHolidaysOnDate(absDt);
if (events) {
// ...
}
} |
Taking a look at this, I have a question for you about how to avoid pulling the Zmanim dependency without breaking backwards compatibility
If we wanted to remove that dependency, how would we handle it? As I'm relatively new to TS, I'm totally open to your suggestions! Do we remove |
Done in c31e007 Sorry; I already implemented all of this (except refactoring the I'm now testing it against leyning. |
Oh, sorry, I didn't realize you were working on this today. I apologize that my getHolidaysOnDate refactor probably caused a bit of a merge mess for you |
Your refactor is actually a duplicate of d0be1bb, except that I didn't touch getHolidaysForYearArray |
Current StatusFrom my POV, this is complete. With #481 and hebcal/hebcal-leyning#473, https://github.com/SLaks/tikkun.io/tree/use-modular works. The refactor shrinks the Tikkun's index chunk from 258KB to 151KB! Possible next steps (I probably will not do these):
|
Thanks for this update. So glad this is working. I think I can safely revert 048f73f as you're the one who originally asked for a way to append suffixes in hebcal/hebcal-leyning#432 and if that's no longer an issue, we may as well go back to the simpler build process and avoid duplicate .d.ts |
Motivation
I wrote some very simple code to run in a browser and print a full year of פרשה names:
When compiled for production using https://vitejs.dev/ with default settings, this produced 150 kB of optimized JS!
Since all functions are contained in the
HebrewCalendar
class and theEvent
hierarchy, Tree Shaking cannot see which APIs are actually used.Suggestion
It ought to be possible to build a new modular API in which application code only
import
s features that are actually used. This should allow tree shaking to entirely drop unused features (eg, emojis, zmanim calculations, unused locales, etc).This would be a new API that requires explicit
import
s to enable more calculations and methods. The existing API would remain as a wrapper to avoid breaking existing code. Applications that want to benefit from tree shaking would need to migrate to the new API to gain the benefits.Details
Making code tree-shakable involves a number of changes (these changes can be made independently for incremental improvements, but each incremental change would require clients to refactor further to get more benefit):
Note: All of these suggestions are rough ideas; I have not reviewed the code carefully enough to be sure that each of these make sense and would actually allow non-trivial amounts of code to be tree-shaken
HebrewCalendar
with separateexport
s to drop unused methods.tachanun.ts
andhallel.ts
easily.he
andhe-x-nonikud
, it would also make sense to movehe-x-nonikud
to a separate file generated at build time, so that projects that only use it can drop nikud entirely.flags
enum with an array ofimport
able objects that contain theirEvent
subclasses and the relevant parts ofgetHolidaysForYear_()
getHolidaysForYear_()
; we should try to estimate how much code this could actually save first.HebrewCalendar.calendar()
with an array ofimport
ed functions or plugins to specify which events you want returned.candleLighting
oromer
), which should be a very big win.Event
subclasses based on the plugins you pass.import
only what they need), and you can then slowly split apart the underlying code to be more modular. This allows you to make incremental improvements under the hood without forcing application code to change further.getHolidaysForYear_()
based on plugins as well for further savings.Event
and subclasses (eg,getEmoji()
; I don't know if there are any other costly members) to a top-levelexport
ed function that takes theevent
as a parameter instead.export
ed function that addsgetEmoji()
toEvent.prototype
, so that it is still available as a member function, but only if this isimport
ed.prototype
declaration, if imported).import
able installer function asasserts Event is {prototype: {getEmoji(): string}}
Let me know if you need help understanding, designing, prototyping, or implementing this.
The text was updated successfully, but these errors were encountered: