flags@4.1.0
Minor Changes
-
#385
201f9d5Thanks @dferber90! - When applications callevaluate()orprecompute()function fromflags/nextit now defers bulk evaluation to the underlying adapters in case those support it, or otherwise falls back to evaluating each flag individually.This speeds up evaluation for applications that need to evaluate multiple flags at once, as the runtime needs to handle fewer promises and more work is reused. In testing we have seen a 20x improvement when called with 100 flags.
import { evaluate } from "flags/next"; import { flagA, flagB } from "../flags"; // pass a list of flags const [valueA, valueB] = await evaluate([flagA, flagB]); // pass an object const { a, b } = await evaluate({ a: flagA, b: flagB });
Adapters can opt into bulk evaluation by implementing a
bulkDecidemethod and setting a stableadapterId. When both are present, flag evaluation groups flags that share the sameadapterIdandidentifysource and invokesbulkDecideonce per group instead of callingdecideper flag. Flags without a bulk-capable adapter still resolve through the normal per-flag path insideevaluate()and still benefit from now reusing the shared per-request headers, cookies, and overrides reads.Tracing reflects this grouping.
evaluate()(and thereforeprecompute()) now emits anevaluatespan carrying aflagCountattribute. Within it, bulk-evaluated flags no longer emit an individual per-flagrunspan; instead each adapter group emits a singlebatchspan (carrying theadapterId, thekeysevaluated in the batch, andcachedCount/overrideCount/decidedCountattributes summarizing how the batch resolved) so per-flag instrumentation overhead is not reintroduced. Flags that fall back to the per-flag path continue to emit their ownflagspan as before.