Skip to content

[print] Simplify custom print-method detection#419

Draft
bbatsov wants to merge 1 commit into
masterfrom
simplify-print-method-detection
Draft

[print] Simplify custom print-method detection#419
bbatsov wants to merge 1 commit into
masterfrom
simplify-print-method-detection

Conversation

@bbatsov

@bbatsov bbatsov commented Jul 15, 2026

Copy link
Copy Markdown
Member

Following up on the concern that #415 brought too much complexity: this strips the mechanism down to its minimum while keeping the behavior.

  • The per-class cache (a deftype holding print-method's method/prefer tables plus a ConcurrentHashMap of verdicts) is gone. custom-print-method? now compares the live get-method result against the generic collection registrations; MultiFn's own dispatch cache does the heavy lifting, and all the staleness/invalidation logic disappears because every lookup sees the current registrations.
  • A new *honor-print-method* dynamic var (default true) gates the feature, making it a per-context decision - the inspector, the debugger or cider-nrepl can bind it off wherever structural output is preferable.
  • The never-crash guards stay: a throwing, ambiguous or stack-overflowing print-method still falls back to structural printing.

Numbers on a collection-heavy benchmark (100 prints of ~4000 nested values): master baseline ~80ms, the cached version ~87ms, this version ~102ms. With the var bound to false there's no overhead at all. I don't think the difference matters for a tooling printer, but if it does, flipping the default to false makes the feature free and purely opt-in - that's a policy call I'm leaving open here.

Net effect: about 50 lines less, no deftype, no atom, no concurrency reasoning.

cc @alexander-yakushev

Drop the per-class cache (deftype + ConcurrentHashMap + generation
tracking) in favor of comparing the live get-method result against the
generic collection registrations - MultiFn's own dispatch cache does
the heavy lifting, and staleness handling disappears because every
lookup sees the current registrations. Add *honor-print-method* so
consumers can turn the whole feature off per context.
@bbatsov
bbatsov force-pushed the simplify-print-method-detection branch from e7ca9b9 to a2ef1e9 Compare July 15, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant