Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 12 additions & 34 deletions js/net/src/ietf/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { type Stream, Writer } from "../stream.ts";
import { Timescale } from "../time.ts";
import type { Groups, Location as TrackLocation, Subscriber as TrackSubscriber } from "../track.ts";
import { untilAborted } from "../util/abort.ts";
import { nextChange } from "../util/change.ts";
import { Deadline, REQUEST_TIMEOUT_MS, requestOptions } from "../util/deadline.ts";
import { LIMITS, type Limits, Slots } from "../util/limits.ts";
import { TimeoutError, withTimeout } from "../util/timeout.ts";
Expand Down Expand Up @@ -1351,21 +1352,10 @@ export class Publisher {
// Subscribe BEFORE reconciling, for the same reason as
// {@link runPublishNamespaces}: a publish landing while an advertisement
// waits for its reply only notifies listeners already registered.
// TODO Make a better helper within Signals.
let dispose!: Dispose;
const changed = new Promise<"changed">((resolve) => {
const table = this.#advertised.changed(() => resolve("changed"));
// A grant change re-diffs the same way, withdrawing what it no longer covers.
// The loop top re-reads the table, so an ended origin still stops it there.
const grant = this.#grant.changed(() => resolve("changed"));
// A token that ended leaves the request carrying it to be made again without.
const ended = this.#auth?.ended.changed(() => resolve("changed"));
dispose = () => {
table();
grant();
ended?.();
};
});
// A grant change re-diffs the same way, withdrawing what it no longer covers.
// The loop top re-reads the table, so an ended origin still stops it there.
// A token that ended leaves the request carrying it to be made again without.
const { changed, dispose } = nextChange(this.#advertised, this.#grant, this.#auth?.ended);

const advertised = this.#advertised.peek();
const updated = advertised ? presented(prefix, advertised, carries) : new Map<Path.Valid, Advertised>();
Expand Down Expand Up @@ -1510,23 +1500,11 @@ export class Publisher {
// for the peer's reply, and a publish that lands in that window notifies
// only the listeners already registered; one created afterwards would sleep
// through it and leave the namespace unadvertised until something unrelated
// changed.
// TODO Make a better helper within Signals.
const changed = new Promise<"changed">((resolve) => {
const table = this.#advertised.changed(() => resolve("changed"));
// A grant change re-diffs the same way, withdrawing what it no longer covers.
// The loop top re-reads the table, so an ended origin still stops it there.
const grant = this.#grant.changed(() => resolve("changed"));
// A token that ended leaves the request carrying it to be made again without.
const ended = this.#auth?.ended.changed(() => resolve("changed"));
const lapsed = this.#lapsed.changed(() => resolve("changed"));
dispose = () => {
table();
grant();
ended?.();
lapsed();
};
});
// changed. A grant change re-diffs the same way, withdrawing what it no longer
// covers; the loop top re-reads the table, so an ended origin still stops it there.
// A token that ended leaves the request carrying it to be made again without.
const change = nextChange(this.#advertised, this.#grant, this.#auth?.ended, this.#lapsed);
dispose = change.dispose;

// The peer no longer holds a namespace whose request ended while idle. The wait
// before offering it again doubles each time, so a peer that ends every one it
Expand Down Expand Up @@ -1569,8 +1547,8 @@ export class Publisher {

// Wait for the next change, which has already fired if one landed above.
const next = await (retry
? race([changed, this.#withdrawal.closing, closed, retryAfter(retry).then(() => advertised)])
: race([changed, this.#withdrawal.closing, closed]));
? race([change.changed, this.#withdrawal.closing, closed, retryAfter(retry).then(() => advertised)])
: race([change.changed, this.#withdrawal.closing, closed]));
dispose?.();
if (!next || next === true) break;
}
Expand Down
17 changes: 4 additions & 13 deletions js/net/src/lite/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { type Timescale, Timestamp } from "../time.ts";
import type * as track from "../track.ts";
import { liteTimescale } from "../track.ts";
import { untilAborted } from "../util/abort.ts";
import { nextChange } from "../util/change.ts";
import { Interests, LIMITS, type Limits, Slots } from "../util/limits.ts";
import { nextTask } from "../util/yield.ts";
import { type Advertised, type Advertisements, sameInstance, wireOf } from "../wire.ts";
Expand Down Expand Up @@ -609,18 +610,8 @@ export class Publisher {
// afterwards would sleep through it, leaving the change unannounced until something
// unrelated moved. A grant change re-diffs the same way, withdrawing what it no longer
// covers and announcing what it now does.
// TODO Make a better helper within Signals.
let dispose: Dispose = () => {};
const arm = () =>
new Promise<"changed">((resolve) => {
const table = this.#advertised.changed(() => resolve("changed"));
const grant = this.#grant?.changed(() => resolve("changed"));
dispose = () => {
table();
grant?.();
};
});
let changed = arm();
const arm = () => nextChange(this.#advertised, this.#grant);
let { changed, dispose } = arm();

try {
// Nothing is announced before the grant it would be checked against. A local close
Expand Down Expand Up @@ -762,7 +753,7 @@ export class Publisher {
if (woke !== "changed") break;

// Re-arm before reading, so an advertise that lands while we write is not lost.
changed = arm();
({ changed, dispose } = arm());

const latest = this.#advertised.peek();
if (!latest) break;
Expand Down
21 changes: 21 additions & 0 deletions js/net/src/util/change.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Dispose, Getter } from "@moq/signals";

/**
* Resolve with "changed" on the next change to any of `sources`, listening from now.
*
* Unlike the lazy `Signal.race`, this registers before the caller's next await, so a change
* landing while it works still wakes the wait. Call `dispose` once done waiting.
*/
export function nextChange(...sources: (Getter<unknown> | undefined)[]): {
changed: Promise<"changed">;
dispose: Dispose;
} {
const { promise: changed, resolve } = Promise.withResolvers<"changed">();
const disposers = sources.map((source) => source?.changed(() => resolve("changed")));
return {
changed,
dispose: () => {
for (const dispose of disposers) dispose?.();
},
};
}
1 change: 0 additions & 1 deletion quest/m0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,5 @@ Each lands its fixes in its own PR and plans only what needs a decision.
- [Release fixed delay](/quest/m0/release-fixed-delay.md) - a fixed latency on `release`, which moq.dev runs, ignores the catalog's jitter and delay as `main` already does
- [Release resubscribe hang](/quest/m0/release-resubscribe-hang.md) - a moq-lite-06 subscription that closes and reopens on `release` is proven to reach the relay, or the hang is fixed and backported
- [CI cost and latency](/quest/m0/ci/README.md) - cloud CI runs only in the merge queue as one `just ci` pass, expensive checks run nightly and gate `release`, caches move to R2, and runners are chosen last
- [Simplification audit](/quest/m0/audit-simplify.md) - overbuilt code and APIs are collapsed, merged, or narrowed into a net simpler whole
- [Lint override and deprecation audit](/quest/m0/audit-lints.md) - every lint suppression is still needed and says why, nothing calls a deprecated API, and stale Rust overrides fail the build
- [Interop audit](/quest/m0/audit-interop.md) - our interop runner entries match what we ship, and every red interop cell with a moq.dev side is fixed, reported, or noted as down
80 changes: 0 additions & 80 deletions quest/m0/audit-simplify.md

This file was deleted.

1 change: 1 addition & 0 deletions quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ lite-07 stream type here.
- [Interop coverage](/quest/m1/interop-coverage/README.md) - the riskiest moq-transport features moq-net exposes get cross-implementation tests over the even drafts 14 to 22
- [Runner nightly](/quest/m1/interop-runner-nightly.md) - a nightly job runs the upstream interop runner against our relay and clients, so newly registered implementations with a published image are tested without a change here
- [CI workflow audit](/quest/m1/audit-ci.md) - every workflow and job gives a signal someone sees, at a cost that signal justifies, or is fixed, moved, or deleted
- [Simplification audit](/quest/m1/audit-simplify.md) - repeat the simplification audit, starting with the m0 leftovers, before the next major release
- [Artifact size audit](/quest/m1/audit-size.md) - binary, FFI, WASM, and bundle growth since the m0 run is explained, fixed, or planned
- [Compile time audit](/quest/m1/audit-compile-time.md) - build-time hotspots are measured against the m0 baselines and the worst are fixed or planned
- [Performance audit](/quest/m1/audit-perf.md) - benchmarks that regressed since the m0 run are explained, fixed, or planned, and unbenched hot paths get coverage
Expand Down
89 changes: 89 additions & 0 deletions quest/m1/audit-simplify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# [M] Simplification audit

## Goal

The code and APIs that cost the most complexity for what they deliver are
simplified: duplicate mechanisms merged, layers, options, and generics with
one user collapsed, and features that don't earn their keep narrowed or
removed. The result is net simpler, even where that means less scope.

## Plan

Recurs once per major release (decided 2026-10-19). The PR that finishes
this run also adds the next one with the same file name at the end of the next
milestone's `Required` (m0 to m1, m1 to m2). The successor keeps the Goal
and this paragraph; the rest of its Plan is rewritten with what this run
learned: baselines, results, and what to check first. A successor placed in m2
also lists the [release cut](/quest/m2/release/cut.md) under `Required`, so it
waits for the release in flight to ship. Only `/quest-delete` ends the
recurrence. Fixes land in the run's PR, one commit each, rather than as follow-ups.
Only a change that needs a maintainer decision (public API, scope) or is
independently landable and too large to review alongside the rest becomes a
follow-up through `/quest-plan`.

Narrowing a feature or reshaping an API is the maintainer's call, so those
are proposals with a recommendation, filed as follow-ups. Unlike the [dead
code audit](/quest/m2/audit-dead-code.md), this targets code that is used but
overbuilt.

### Check first

Left from the m0 run because open work edited the same code (close-tail drain
landed in [#5762](https://github.com/moq-dev/moq/pull/5762)):

- `ietf/session.rs` `start()` builds both halves twice across the draft arms,
and the IETF publisher/subscriber constructors drifted from lite's config
structs.
- Lite and IETF `GroupServe` share their open, flush, and FIN-settle driver.
- `ietf/adapter.rs` reimplements `kio::Queue`; keep a drop guard for the
writer.

Maintainer proposals from m0, not yet planned, each with its recommendation:

- Yes: a moq-video raw-frame publisher that moq-ffi and moq-c both wrap,
removing about 250 duplicated encode and bandwidth-follow lines. moq-c's
copy calls `pollster::block_on(set_bitrate)` on the C runtime while holding
the encoder lock, which may stall other moq-c tasks (unverified).
- Yes, after the publisher: move the bindings' duplicated `Background` into
moq-tokio, with a blanket `Driver for &mut D` in moq-net.
- Yes: make Python's `connect` the `Client` class, dropping a 27-parameter
forwarding signature.
- No: typealias the Swift wrapper's forwarding classes. The wrapping is
deliberate (argument labels, no `Moq` prefixes), and it would break Swift.
- Keep: Kotlin's `AnnounceConsumer.updates()` cancels on every completion
while the other flows cancel only on cancellation; its doc promises that.

The Go wrapper's `Server.Accept` and handle-returning methods skip
`bridge.CallHandle`, which may leak an accepted handle on cancellation. This
is unverified and worth its own investigation.

### Results (m0, 2026-10-20)

Three PRs, all private and behavior-preserving:
[#5977](https://github.com/moq-dev/moq/pull/5977),
[#6049](https://github.com/moq-dev/moq/pull/6049), and this run's final PR.
They merged the JSON stream consumer into the byte stream consumer, one IETF
request-error writer in Rust and JS, Rust's lite version gates mirrored in
JS, one moq-c task slab with no never-`None` entries, one moq-c media consume
path, one Kotlin pull adapter, one Python async stream base, small Go
duplicates, one queue-once keyed waker in moq-net, and one armed change wait
in js/net's publishers.

### Kept on purpose

- Backend and playback traits have several implementations or device-free
test doubles; catalog traits erase application extension types.
- The ietf publisher's `RequestWaker` and lite's `FetchWake` stay apart from
the queue-once waker: one collects into a list and wakes an owner, the
other fills a set.
- js/net's subscriber grant checks stay hand-written: `auth_gate.ts` `Gate`
only checks publish grants, and a direction flag costs what it saves.
- The JS datagram send and receive loops: the lite and IETF error handling
and `served` bookkeeping differ, so a shared loop needs hooks.
- Dart and C++ wrappers are already thin.

Transport adapter deduplication and compression removal have dedicated work;
avoid a second design here. Start with the items above, then the largest
modules again, and the bindings' forwarding layers. The largest moq-net
modules at the end of m0: `ietf/publisher.rs` 16,047 lines,
`model/origin.rs` 11,863, and `lite/subscriber.rs` 7,181.
Loading
Loading