Skip to content

Improve incremental generator caching #1791

Closed

Description

@TimothyMakkison

While working on a more source generated approach, I noticed that Refit does not correctly use incremental generator caching. While a previous PR uses some of the more modern techniques such as CreateSyntaxProvider, the lines 829-846 are functionally useless and will never successfully cache anything. This is due to how both ImmutableArray handles equality and the passing of the reference type Compilation (this will always change between re-runs).

  • Methods should be represented by a structurally comparable object
  • A benchmark could be created to confirm the benefits. Its possible that generating the code in a single pass is faster than caching.
  • Tests should be added to verify that the caching works as intended
  • Why is PreserveAttribute.cs added and then its namespace queried? Would the compiler change this? I assume it would always be global::RefitInternalGenerated.PreserveAttribute
  • CancellationToken should be respected to reduce IDE lag

I'll start work on a PR for this but I don't promise anything.

Related #1389

Activity

  1. ChrisPulman commented on Aug 27, 2024

    @ChrisPulman
    Member

    Thanks Tim, much appreciated, I was going to head down the same rabbit hole and try to make things better, I see that AoT is important to many people too :)

  2. TimothyMakkison commented on Aug 31, 2024

    @TimothyMakkison
    CollaboratorAuthor

    Hey, added some preliminary benchmarks in #1798.

    I was planning on adding some tests to verify steps in the incremental generator like I've done for Mediator. I used WithTrackingName to check specific steps. Unfortunately this is only available in Roslyn 4.1+. I believe I could either:

    • Update InterfaceStubGenerator.Roslyn40 to InterfaceStubGenerator.Roslyn41 (probably a breaking change)
    • Add InterfaceStubGenerator.Roslyn41 and use it for the tests.
  3. github-actions commented on Oct 26, 2024

    @github-actions

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  4. locked as resolved and limited conversation to collaborators on Oct 26, 2024
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions