-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
[typescript-angular] refactor service classes for reducing bundle sizes by ~20% #20681
[typescript-angular] refactor service classes for reducing bundle sizes by ~20% #20681
Conversation
This reduces bundle sizes of ESM bundles on the order of 20%.
@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka @joscha anyone up for a review? happy about any feedback :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pull request!
Look good to me.
Personally, I would define all those helpers as standalone functions instead of a class to inherit from. But it's more of a stylistic choice - should be good either way
+1 @daniel-sc would you be able to do that in a follow-up PR? |
@macjohnny @amakhrov Generally, I'm also favouring standalone functions, but here the parent class has the advantage of not repeating the member delcaration (see below) in each service class, which most likely has some impact on the bundle size - don't you think? protected basePath = '';
public defaultHeaders = new HttpHeaders();
public configuration: {{configurationClassName}};
public encoder: HttpParameterCodec; |
can you try it out? |
@daniel-sc Hi, Could you please take a look at this comment?: 5f92de4#r153539042 |
@macjohnny finally found some time to test wether switching from the inheritance approach to static utils has some impact on the bundle size. For our project (larger spec) I get the following results:
So the current approach's bundle size is ~1% smaller. |
This reduces bundle sizes of ESM bundles on the order of 20%.
Example (using https://esbuild.github.io/analyze/ on the result of
ng build --stats-json
):original:
new:
@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka @joscha
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming7.x.0
minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)