Skip to content

perf(compiler-cli): use BindingType enum check in suffix-not-supported extended diagnostic#68767

Draft
arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:perf/compiler_cli_suffix-not-supported
Draft

perf(compiler-cli): use BindingType enum check in suffix-not-supported extended diagnostic#68767
arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:perf/compiler_cli_suffix-not-supported

Conversation

@arturovt
Copy link
Copy Markdown
Contributor

Replaces the node.keySpan.toString().startsWith('attr.') string allocation in the suffixNotSupported extended template check with an O(1) node.type === BindingType.Attribute enum comparison.

The diagnostic message string is also extracted to a module-level constant so it is created once at module load time instead of on every diagnostic emit.

Additionally, this change adds missing test coverage for the .% and .em suffixes, as well as for a plain attr. binding without a style suffix.

Measured with a 100-iteration microbenchmark before and after the change (MacBook Pro 2018, Intel CPU):

const start = performance.now();
for (let i = 0; i < 100; i++) {
  new ExtendedTemplateCheckerImpl(templateTypeChecker, program.getTypeChecker(),
    [suffixNotSupportedFactory], {}).getDiagnosticsForComponent(component);
}
console.log((performance.now() - start) / 100, 'ms/iter');

Before: ~0.24 ms/iter
After: ~0.14 ms/iter (~40% faster)

…d extended diagnostic

Replaces the `node.keySpan.toString().startsWith('attr.')` string allocation in the `suffixNotSupported` extended template check with an O(1) `node.type === BindingType.Attribute` enum comparison.

The diagnostic message string is also extracted to a module-level constant so it is created once at module load time instead of on every diagnostic emit.

Additionally, this change adds missing test coverage for the `.%` and `.em` suffixes, as well as for a plain `attr.` binding without a style suffix.

Measured with a 100-iteration microbenchmark before and after the change (MacBook Pro 2018, Intel CPU):

```ts
const start = performance.now();
for (let i = 0; i < 100; i++) {
  new ExtendedTemplateCheckerImpl(templateTypeChecker, program.getTypeChecker(),
    [suffixNotSupportedFactory], {}).getDiagnosticsForComponent(component);
}
console.log((performance.now() - start) / 100, 'ms/iter');
```

Before: `~0.24 ms/iter`
After: `~0.14 ms/iter` (~40% faster)
@angular-robot angular-robot Bot added area: performance Issues related to performance area: compiler Issues related to `ngc`, Angular's template compiler labels May 17, 2026
@ngbot ngbot Bot added this to the Backlog milestone May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: compiler Issues related to `ngc`, Angular's template compiler area: performance Issues related to performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant