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

perf(@angular/build): use direct transpilation with isolated modules #27752

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

clydin
Copy link
Member

@clydin clydin commented May 30, 2024

When using the application builder and the TypeScript isolatedModules option is enabled and script sourcemaps are disabled, TypeScript code will be transpiled via the bundler instead of the current behavior of using TypeScript. The use of the isolatedModules option ensures that TypeScript code can be safely transpiled without the need for the type-checker. This mode of operation has several advantages. The bundler (esbuild in this case) will know have knowledge of the TypeScript code constructs, such as enums, and can optimize the output code based on that knowledge including inlining both const and regular enums where possible. Additionally, this allows for the removal of the babel-based optimization passes for all TypeScript code. These passes are still present for all JavaScript code such as from third-party libraries/packages. These advantages lead to an improvement in build time, especially in production configurations. To ensure optimal output code size in this setup, the useDefineForClassFields TypeScript option should either be removed or set to true which enables ECMAScript standard compliant behavior.

Initial testing reduced a warm production build of a newly generated project from ~2.3 seconds to ~2.0 seconds.

@clydin clydin added the target: minor This PR is targeted for the next minor release label May 30, 2024
@clydin clydin force-pushed the application/angular-direct-transpile branch 3 times, most recently from 3ee9073 to ea8e2fc Compare May 30, 2024 18:41
@clydin clydin force-pushed the application/angular-direct-transpile branch 3 times, most recently from 7e58dfd to 28e5eb5 Compare May 31, 2024 14:49
When using the application builder and the TypeScript `isolatedModules`
option is enabled and script sourcemaps are disabled, TypeScript code
will be transpiled via the bundler instead of the current behavior of
using TypeScript. The use of the `isolatedModules` option ensures that
TypeScript code can be safely transpiled without the need for the type-checker.
This mode of operation has several advantages. The bundler (esbuild in this case)
will know have knowledge of the TypeScript code constructs, such as enums, and can
optimize the output code based on that knowledge including inlining both
const and regular enums where possible. Additionally, this allows for
the removal of the babel-based optimization passes for all TypeScript
code. These passes are still present for all JavaScript code such as
from third-party libraries/packages. These advantages lead to an
improvement in build time, especially in production configurations.
To ensure optimal output code size in this setup, the `useDefineForClassFields`
TypeScript option should either be removed or set to `true` which
enables ECMAScript standard compliant behavior.

Initial testing reduced a warm production build of a newly generated
project from ~2.3 seconds to ~2.0 seconds.
@clydin clydin force-pushed the application/angular-direct-transpile branch from 28e5eb5 to 5bb936c Compare June 5, 2024 14:56
@clydin clydin marked this pull request as ready for review June 5, 2024 14:57
@clydin clydin requested a review from alan-agius4 June 5, 2024 14:58
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jun 5, 2024
Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!

@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jun 5, 2024
@clydin clydin merged commit 3acb776 into angular:main Jun 5, 2024
33 checks passed
@clydin clydin deleted the application/angular-direct-transpile branch June 5, 2024 15:38
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants