CONCEPT Cited by 1 source
Opt-in marker interface¶
Definition¶
An opt-in marker interface is an interface (or protocol, or trait, depending on language) whose sole purpose is for an implementor to declare opt-in participation in some cross-cutting framework behaviour. Unlike rich interfaces that prescribe real methods, a marker interface's primary contract is "I implement this → the platform should treat me specially."
Pinterest's PerfImageView / PerfTextView / PerfVideoView are marker interfaces-with-readiness-methods (a hybrid: small method surface, but the primary semantics is the opt-in declaration). A product engineer marks their ImageView as a PerfImageView to tell the platform: "this image is content-critical; count it toward Visually Complete." (Source: sources/2026-04-08-pinterest-performance-for-everyone).
Why opt-in and not auto-detect¶
Pinterest's platform could, in principle, auto-detect every ImageView in the view tree. Instead it requires the product engineer to explicitly tag each view that should count. Opt-in rather than auto-detect is a deliberate design choice:
- False-positive avoidance — not every
ImageViewon screen matters for Visually Complete (loading shimmers, decorative chrome, background imagery, collapsed UI elements). Auto-detection would block Visually Complete on every strayImageViewthat happens to be slow, producing never-ready or late-ready signals. - Product intent is not observable — the platform can't tell from a view's type whether it carries content-critical meaning. Only the product engineer knows whether this particular hero image is the one the user is waiting for.
- Tagging is cheap — implementing a marker interface is one import and a few lines; the cost of opt-in per view is minutes.
- Discoverability — the marker makes the performance-relevant views grep-able and lintable.
Related language mechanisms¶
- Java / Kotlin marker interface (
Serializable,Cloneable) — classical pure-marker use. - Go marker interface (empty interface,
type MyMarker interface {}) — same idea. - Rust trait — traits serve both prescriptive (
fn fmt(&self) -> ...) and marker (Send,Sync,Copy) roles. - Swift protocol conformance — protocols can be pure-marker or prescriptive.
- C# attribute / Java annotation (
@Instrumented,@Loggable) — non-interface way to achieve the same opt-in semantics without forcing a type relationship.
Pinterest's hybrid of marker with small readiness method sits between pure-marker (nothing prescribed) and rich-interface (full behaviour contract). The marker half carries the opt-in signal; the method half lets the platform consume per-instance state without reaching into private implementation.
The load-bearing correctness property: tagging accuracy¶
The whole scheme's correctness depends on product engineers tagging exactly the right views:
- False negatives (critical view not tagged) → Visually Complete fires before the user-perceivable content is actually visible → metric under-reports latency.
- False positives (irrelevant view tagged) → Visually Complete blocked on a view the user doesn't care about → metric over-reports latency or never fires.
Production-quality opt-in instrumentation typically adds guardrails:
- Lint rules — flag common omissions ("this
ImageViewis at the top of aBaseSurfaceand is not aPerfImageView"). - Code review conventions — performance-critical PRs get reviewed by the Perf team.
- Baseline validation — A/B test Visually Complete timestamps against human-rater video review to catch drift.
Pinterest's post doesn't describe any of these guardrails — opt-in correctness is an open question left to the implementor.
Related to / distinguished from¶
- Annotations (Java, Kotlin, Python decorators) — a non-type-system way to achieve opt-in; often paired with annotation processors or reflection at runtime.
- Composition over inheritance — delegates or subscriber objects can carry the opt-in semantic without forcing a type relationship; trades off discoverability for flexibility.
- Registration APIs — "call
perfTracker.register(this)inonCreate" — the imperative analogue; trades static type-system guarantees for runtime flexibility.
Seen in¶
- 2026-04-08 Pinterest — Performance for Everyone (sources/2026-04-08-pinterest-performance-for-everyone) — canonical;
PerfImageView/PerfTextView/PerfVideoViewas hybrid marker-plus-readiness interfaces; product-engineer-tagged opt-in; consumed byBaseSurfaceview-tree walk.