exp 168: reject Database resolved-runtime cache#164
Open
danReynolds wants to merge 1 commit into
Open
Conversation
Mirror exp 159's `_sendPort` cache one layer up: a sync-readable `_resolvedRuntime` field on `Database` so post-open `select` / `selectBytes` / `execute` / `executeBatch` / `transaction` skip the `await _runtime` microtask hop. Two order-flipped passes on writer_pipelining.dart produced alternating-sign deltas inside per-round variance — sequential-awaited -2.3% / +2.5%, transaction-guardrail -7.5% / +6.1%, concurrent-burst +4-5% both passes — so the ~1-2 us per-call hop sits at or below the focused-harness floor. No runtime code kept. Database-layer microtask hop trimming above the writer no longer moves exp 159's sequential-write residual floor; the next reduction candidate must reduce round-trip count (group commit) or change transport, not chase hops. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hypothesis
Exp 159 attacked fixed per-round-trip overhead inside
Writer._requestbycaching
_sendPortand removing theawait _workerPort.futuremicrotaskhop. Every public
Databasemethod (select,selectBytes,execute,executeBatch,transaction) still doesfinal ... = await _runtime;atthe top — one microtask hop above the writer/reader call, on every Database
method call, because
_runtimeis already-resolved after open.If exp 159's residual is really port-wake + event-loop scheduling, the
same pattern at the layer above should chip another hop off every call. At
~1-2 µs per hop the upper bound on
sequential-awaited (2000 writes)is~2-4 ms out of a ~32 ms median: theoretical ~6-12%, comfortably above the
focused-benchmark noise band exp 159 used to accept its win.
Approach
lib/src/database.dart:_DatabaseRuntime? _resolvedRuntime.Future.sync(() async { ... })body, after spawnawaits complete, assign the runtime record to
_resolvedRuntimebeforereturn runtime.final ... = await _runtime;withfinal ... = _resolvedRuntime ?? await _runtime;at 5 call sites.closeanddiagnosticskeepawait _runtime— cold.streamkeepsStream.fromFuture(_runtime).asyncExpand(...)— one-shotper stream creation.
No public API change. No new measurement scaffolding.
Results
dart run benchmark/experiments/writer_pipelining.dart, two passes, 7rounds each, order flipped between passes per the JOURNAL "phase-ordered
A/B" lesson.
Sequential-awaited and transaction-guardrail flip sign between passes at
the same magnitude as round-to-round variance. Concurrent-burst trends
small-positive (regression) both passes but inside the per-round spread.
dart analyze lib: clean.dart test test/database_test.dart test/stream_test.dart: 75/75 pass.Outcome
Rejected — below the focused-benchmark noise floor across two
order-flipped passes. The theoretical 6–12% headroom did not show up in
measured wall time; deltas alternate sign between passes at the same
magnitude as single-phase variance. Same shape as the recent
overhead-removal rejection cluster (exp 145, exp 148, exp 151): once
per-call cost drops below ~2 µs the focused harness can't separate it
from machine jitter.
No runtime code kept. Exp 159's "further reduction needs request batching
across calls (group commit) or a different transport" framing remains the
correct steering for the sequential-write floor. Would reopen if a future
measurement system can resolve sub-1 µs per-call deltas on real
workloads.
Test plan
dart analyze lib— cleandart test test/database_test.dart— 49/49 passdart test test/stream_test.dart test/stream_invalidation_coalescing_test.dart test/stream_cache_hit_reliability_test.dart— passdart test test/stream_dependency_shapes_test.dart test/stream_overflow_fallback_test.dart test/stream_trigger_cascade_test.dart— passdart run benchmark/finalize_experiment.dart --experiment=experiments/168-resolved-runtime-cache.md— green🤖 Generated with Claude Code