Skip to content

Add a rule against static state and defaulting to Lazy<T> - #763

Closed
ChrisonSimtian wants to merge 1 commit into
Fallout-build:developfrom
ChrisonSimtian:docs/avoid-lazy-rule
Closed

ChrisonSimtian wants to merge 1 commit into
Fallout-build:developfrom
ChrisonSimtian:docs/avoid-lazy-rule

Conversation

@ChrisonSimtian

@ChrisonSimtian ChrisonSimtian commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Static mutable state leaks between runs. That is what epic #315 removes. Lazy<T> also adds a delegate and a check on every read, and that cost shows up in run time and CI time. Both came up in review of #453: Lazy<InMemorySink> wrapped an empty list, and the replacement static readonly field still holds a mutable list.

Outcome

AGENTS.md gets rule 10:

  • Prefer an instance owned by the run's context or a service. No static.
  • static readonly is fine for immutable values only. readonly stops reassignment, not changes to the contents.
  • Lazy<T> only for expensive work that is often not needed. Never on a hot path.

Out of scope

  • Existing statics and Lazy<T> uses. Each needs its own review.
  • No code changes.

@ChrisonSimtian ChrisonSimtian added release/Next Targets the next release skip-changelog Dont add to the Github Release Notes labels Nov 22, 2026
A static readonly field only stops reassignment, so a mutable object in one is still shared between runs. Lazy<T> adds a delegate and a check on every read, which costs run time and CI time. The rule asks for context-owned instances first, static readonly only for immutable values, and Lazy<T> only for expensive, rarely needed work.
@ChrisonSimtian ChrisonSimtian changed the title Add a rule against defaulting to Lazy<T> Add a rule against static state and defaulting to Lazy<T> Nov 22, 2026
@ChrisonSimtian

Copy link
Copy Markdown
Collaborator Author

@dennisdoomen I noticed claude going a bit wild with this, do you want to put this into your Skills PR instead?

@dennisdoomen

Copy link
Copy Markdown
Collaborator

Yeah, that needs to go into my agents/skills PR.

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

Labels

release/Next Targets the next release skip-changelog Dont add to the Github Release Notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants