-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[typescript-angular] refactor service classes for reducing bundle sizes by ~20% #20681
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
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 :) |
amakhrov
left a comment
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. |
…stache` The new BaseService was added in OpenAPITools#20681, but the license information was not added.
The new BaseService was added in OpenAPITools#20681, but the license information was not added.
The new BaseService was added in #20681, but the license information was not added.
|
@daniel-sc I thought about an optimization like this too (I'm a bit late though xD). I wonder if you added the possibility to generate a global |
|
@mirobo not sure I understand. The base service is generated once per execution of the generator - normally if you have multiple separate APIs, you'd have separate folders with generated code (or even separate packages), so it would not make too much sense to "share" the base service. Also the base service is rather small, so the overhead of duplicating it is comparably low. |
you understood correctly, but I see the filesize overhead is minimal.. I didn't yet check in detail how all files are bundled, but I have around 15+ generated API clients (will only grow in the future), but maybe the best solution would be to lazy-load some of the clients. Generally I could think of a new type of client once Angular offers a "httpResource" variant specifically for POST/PUT.. would MAYBE would require less boilerplate (the boilerplate would be in Angular itself 😅). |
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.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)