Skip to content

Commit 1433dc8

Browse files
MarcoDotIOclaude
andcommitted
perf(client): repeated server settings keep the same settings object
Settings decode their background intervals into Durations, which are new instances on every push. reuseUnchanged replaced any non-plain object, so an unchanged settings push or reconnect snapshot still produced a new settings and config object. Values that implement Equal are now reused when equal. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a8d6b0e commit 1433dc8

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎packages/client-runtime/src/state/serverConfigProjection.test.ts‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
import type { ServerConfig, ServerConfigStreamEvent } from "@t3tools/contracts";
1+
import {
2+
DEFAULT_SERVER_SETTINGS,
3+
ServerSettings,
4+
type ServerConfig,
5+
type ServerConfigStreamEvent,
6+
} from "@t3tools/contracts";
27
import * as Option from "effect/Option";
8+
import * as Schema from "effect/Schema";
39
import { describe, expect, it } from "vite-plus/test";
410

511
import { applyServerConfigProjection, reuseUnchanged } from "./serverConfigProjection.ts";
612

13+
const encodeSettings = Schema.encodeSync(ServerSettings);
14+
const decodeSettings = Schema.decodeSync(ServerSettings);
15+
716
describe("reuseUnchanged", () => {
817
const provider = (checkedAt: string, skills: ReadonlyArray<string>) => ({
918
instanceId: "claude",
@@ -53,4 +62,20 @@ describe("applyServerConfigProjection settingsUpdated", () => {
5362
expect(nextSettings.providerInstances.codex).toBe(settings.providerInstances.codex);
5463
expect(nextSettings.providerInstances.claude.config.launchArgs).toBe("--verbose");
5564
});
65+
66+
it("keeps the settings object when an update repeats the current settings", () => {
67+
const wire = encodeSettings(DEFAULT_SERVER_SETTINGS);
68+
const decode = () => decodeSettings(structuredClone(wire));
69+
const settings = decode();
70+
const current = Option.some({
71+
config: { settings } as unknown as ServerConfig,
72+
latestEvent: {} as ServerConfigStreamEvent,
73+
source: "live" as const,
74+
});
75+
const next = applyServerConfigProjection(current, {
76+
type: "settingsUpdated",
77+
payload: { settings: decode() },
78+
} as ServerConfigStreamEvent);
79+
expect(Option.getOrThrow(next).config.settings).toBe(settings);
80+
});
5681
});

‎packages/client-runtime/src/state/serverConfigProjection.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ServerConfig, ServerConfigStreamEvent } from "@t3tools/contracts";
2+
import * as Equal from "effect/Equal";
23
import * as Option from "effect/Option";
34

45
export interface ServerConfigProjection {
@@ -44,6 +45,8 @@ export function reuseUnchanged<T>(previous: unknown, next: T): T {
4445
});
4546
return (same ? previous : merged) as T;
4647
}
48+
// Decoded settings carry Durations, which are fresh instances on every push.
49+
if (Equal.isEqual(next)) return (Equal.equals(previous, next) ? previous : next) as T;
4750
if (Object.getPrototypeOf(next) !== Object.prototype) return next;
4851
const before = previous as Record<string, unknown>;
4952
const after = next as Record<string, unknown>;

0 commit comments

Comments
 (0)