Skip to content

Performance conformance compile-time checks #42690

Open

Description

@mgechev

Feature Request

Relevant Package

@angular/compiler and @angular/compiler-cli

Description

Introduce compile-time conformance checks to guard against performance anti-patterns.

Describe the solution you'd like

The Angular compiler can perform extra checks on the user application to guard against common pitfalls. We already have the available parsing and reporting infrastructure, and there's work happening in the direction of expanding the number of compile-time checks.

A few examples of helpful performance conformance rules are:

  • Find all the unused components, directives, and pipes in the hierarchy of @NgModule and report them.
  • Inline styles within component templates. They are going to break CSS inlining and also view encapsulation.
  • Prevent adding fonts within component template. Rather, prefer adding fonts globally to index.html.
  • Check if there's a relative anchor without a routerLink attribute. This is often a user mistake that can cause the page to reload rather than trigger a client-side navigation

Describe alternatives you've considered

An alternative is to delegate these checks to linters, such as eslint or codelyzer (now deprecated). Even though this would reduce maintenance, we'd also be limited to only applications using the linting tooling and have explicitly enabled these checks.

Activity

  1. added
    feature
    area: compiler
    on Jun 28, 2021
  2. added this to the Backlog milestone on Jun 28, 2021
  3. sod commented on Jul 1, 2021

    @sod
    Contributor

    you could add to the list:

    getObservable() | async // <- of course this can work, if the return value is in some form memoized, but in 99% of cases, that developer didn't yet fully understand observables.

  4. sahilpurav commented on Jul 6, 2021

    @sahilpurav

    This is what I'm also looking. I'm happy to contribute on this feature.

  5. mgechev commented on Jul 9, 2021

    @mgechev
    MemberAuthor

    @sod since these would be compile-time errors, we want 100% certainty rather than having a confidence interval.

  6. dgp1130 commented on Jan 28, 2022

    @dgp1130
    Contributor

    These could be a good candidate for extended diagnostics now that it has launched. We should consider which of these checks may make sense as a diagnostic.

    • Find all the unused components, directives, and pipes in the hierarchy of @NgModule and report them.

    Probably difficult to implement as an extended diagnostic and IMHO very annoying when developing. I could see some folks disabling this check by default, but enabling it for CI, though even that would prevent incremental additions and could be frustrating.

    • Inline styles within component templates. They are going to break CSS inlining and also view encapsulation.

    Could definitely ban <style /> tags in Angular templates. Would definitely save some debugging time.

    • Prevent adding fonts within component template. Rather, prefer adding fonts globally to index.html.

    Would this be handled by banning <style />? Is it possible to define fonts outside of CSS? Is this some kind of <link /> tag we would want to ban?

    • Check if there's a relative anchor without a routerLink attribute. This is often a user mistake that can cause the page to reload rather than trigger a client-side navigation

    This sounds like an easy win for an extended diagnostic.

  7. mgechev commented on Feb 10, 2022

    @mgechev
    MemberAuthor

    Would this be handled by banning <style />? Is it possible to define fonts outside of CSS? Is this some kind of tag we would want to ban?

    Yep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: compilerfeature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions