ArchUnitNET icon indicating copy to clipboard operation
ArchUnitNET copied to clipboard

[Feature Request] Add caching mechanism to improve performance on large projects

Open mokarchi opened this issue 5 months ago • 0 comments

Motivation

When using ArchUnitNET in large .NET solutions with many assemblies, running architecture tests in CI pipelines can become very slow. Currently, ArchLoader().LoadAssemblies(...).Build() always scans assemblies from scratch on every test run.

In ArchUnit for Java, this problem was solved by introducing a caching layer for the imported architecture model. This significantly reduced execution time by avoiding redundant scanning when assemblies did not change.

Proposal

Introduce a caching mechanism in ArchUnitNET core:

  • In-memory cache: Reuse the already loaded Architecture model within the same test run.
  • Persistent cache: Serialize the Architecture object to disk and reload it in subsequent runs, if assemblies have not changed.

Cache invalidation

The cache should be invalidated if:

  • An assembly file has changed (e.g. hash or timestamp).
  • ArchUnitNET version changes (internal model may not be compatible).
  • [Optional] Additional cache key provided by user.

Benefits

  • Greatly improves performance in CI/CD pipelines for large solutions.
  • Aligns ArchUnitNET with the Java version, which already supports caching.
  • Reduces feedback time for developers running tests locally.

mokarchi avatar Sep 08 '25 18:09 mokarchi