Skip to content

perf(core): tree-shake the profiler event enum out of applications - #71955

Open
arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:perf/core-tree-shake-profiler-event
Open

arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:perf/core-tree-shake-profiler-event

Conversation

@arturovt

Copy link
Copy Markdown
Contributor

Prior to this commit every application shipped the runtime ProfilerEvent object, because the framework's own profiler calls referenced it. Only Angular DevTools reads that object, and its reverse number to name map is never read at all.

Internal calls now use an inlined const enum, so they compile down to plain numbers. The runtime enum is still exported as ɵProfilerEvent for DevTools, and the application bundler now drops it: about 1.8 kB less raw JavaScript, around 350 bytes gzipped, in every Angular application.

Prior to this commit every application shipped the runtime `ProfilerEvent`
object, because the framework's own profiler calls referenced it. Only Angular
DevTools reads that object, and its reverse number to name map is never read at
all.

Internal calls now use an inlined `const enum`, so they compile down to plain
numbers. The runtime enum is still exported as `ɵProfilerEvent` for DevTools,
and the application bundler now drops it: about 1.8 kB less raw JavaScript,
around 350 bytes gzipped, in every Angular application.
@pullapprove
pullapprove Bot requested a review from kirjs November 11, 2026 12:29
@angular-robot angular-robot Bot added area: performance Issues related to performance area: core Issues related to the framework runtime labels Nov 11, 2026
@ngbot ngbot Bot added this to the Backlog milestone Nov 11, 2026
* applications no longer ship the runtime `ProfilerEvent` object, which only Angular DevTools
* reads. The members must stay identical to `ProfilerEvent`, which `profiler_spec.ts` asserts.
*/
export const enum ProfilerEvent {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't like very much that this is a distinct enum.
If the one in packages/core/primitives/devtools/src/profiler_types.ts is changed, nothing will warn us here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the drift is covered bc the assertion in profiler_spec.ts is typed against both enums, so adding or removing a member on either side fails to compile, and re-numbering fails the test

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

BUT i can move that const enum into profiler_types.ts next to the public enum and initialize the public members from it (TemplateCreateStart = ProfilerEventInternal.TemplateCreateStart). Values can then never diverge, and a member added to the public enum fails immediately, WDYT?

@JeanMeche JeanMeche Nov 11, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And why not make the enum a const object (and also expose its type) ?

@JeanMeche
JeanMeche requested review from JeanMeche and removed request for kirjs November 11, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Issues related to the framework runtime area: performance Issues related to performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants