DedupingHook

public final class DedupingHook : HookDecorator

Wraps a hook so that repeated evaluations resolving to the same result do not reach it again within a time window.

The wrapped hook is told about a flag when its result changes, and at most once per window while the result stays the same. This is useful for reducing the telemetry volume produced by frequent re-evaluations, for example a flag that is read on every redraw of a view. Deduplication is opt-in: a hook that is registered unwrapped observes every evaluation.

This class is not stable, and not subject to any backwards compatibility guarantees or semantic versioning. It is experimental.

config.hooks = [
    MetricsHook(),                                     // observes every evaluation
    DedupingHook(ObservabilityHook()),                  // default window
    DedupingHook(TelemetryHook(), window: 60),
    DedupingHook(ExperimentHook(), deduper: sharedDeduper)
]

Two evaluations resolve to the same result when they agree on everything EvaluationExposureKey describes.

An evaluation the SDK has no flag data for resolves to the default value, and is the same result as another that does. Evaluations made before the client has flags are of that kind, so the wrapped hook is told about one of them and then told about the flag again as soon as its data arrives.

A suppressed evaluation reaches neither beforeEvaluation nor afterEvaluation, because hooks pair their stages. The identify and track stages are always forwarded. Analytics events are unaffected: feature, debug, and summary events are still recorded for every evaluation, so the evaluation counts LaunchDarkly reports for your flags do not change.

What the wrapped hook has been told about is cleared by LDClient.identify(context:), so the first evaluation of each flag after an identify always reaches it.

Give each hook its own instance unless you intend hooks to share a window: the first hook to be told about an evaluation starts the window that suppresses the rest.

Wrap outermost when you stack hooks that wrap other hooks. Suppressing an evaluation means returning series data that says so in place of what the stage was given, so a wrapper outside this one does not get back what it stored in its own before stage. A wrapper inside this one is unaffected, since a suppressed evaluation never reaches it.