Skip to content

Commit 14ac1b5

Browse files
authored
Use a single instance of cfc object when traversing (#1912)
Added the better performance test in this branch
1 parent e817c4c commit 14ac1b5

File tree

4 files changed

+11412
-11630
lines changed

4 files changed

+11412
-11630
lines changed

packages/memory/space-schema.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
ContextualFlowControl,
23
deepEqual,
34
type JSONObject,
45
type JSONValue,
@@ -48,7 +49,7 @@ import {
4849
type SelectedFact,
4950
selectFact,
5051
selectFacts,
51-
type Session,
52+
type Session as SpaceStoreSession,
5253
toSelection,
5354
} from "./space.ts";
5455

@@ -77,7 +78,7 @@ export class ServerObjectManager extends BaseObjectManager<
7778
private restrictedValues = new Set<string>();
7879

7980
constructor(
80-
private session: Session<MemorySpace>,
81+
private session: SpaceStoreSession<MemorySpace>,
8182
private providedClassifications: Set<string>,
8283
) {
8384
super();
@@ -150,7 +151,7 @@ export class ServerObjectManager extends BaseObjectManager<
150151
}
151152

152153
export const selectSchema = <Space extends MemorySpace>(
153-
session: Session<Space>,
154+
session: SpaceStoreSession<Space>,
154155
{ selectSchema, since, classification }: SchemaQuery["args"],
155156
): FactSelection => {
156157
const startTime = performance.timeOrigin + performance.now();
@@ -163,6 +164,7 @@ export const selectSchema = <Space extends MemorySpace>(
163164
Immutable<JSONValue>,
164165
SchemaContext | undefined
165166
>();
167+
const cfc = new ContextualFlowControl();
166168
const schemaTracker = new MapSet<string, SchemaPathSelector>(deepEqual);
167169

168170
const includedFacts: FactSelection = {}; // we'll store all the raw facts we accesed here
@@ -188,6 +190,7 @@ export const selectSchema = <Space extends MemorySpace>(
188190
entry,
189191
selectorEntry.value,
190192
tracker,
193+
cfc,
191194
schemaTracker,
192195
);
193196

@@ -253,6 +256,7 @@ function loadFactsForDoc(
253256
fact: IAttestation,
254257
selector: SchemaPathSelector,
255258
tracker: PointerCycleTracker,
259+
cfc: ContextualFlowControl,
256260
schemaTracker: MapSet<string, SchemaPathSelector>,
257261
) {
258262
if (isObject(fact.value)) {
@@ -266,6 +270,7 @@ function loadFactsForDoc(
266270
factValue,
267271
selector.path,
268272
tracker,
273+
cfc,
269274
schemaTracker,
270275
selector,
271276
);
@@ -294,7 +299,7 @@ function loadFactsForDoc(
294299

295300
const redactCommits = <Space extends MemorySpace>(
296301
includedFacts: FactSelection,
297-
session: Session<Space>,
302+
session: SpaceStoreSession<Space>,
298303
) => {
299304
const change = getChange(includedFacts, session.subject, COMMIT_LOG_TYPE);
300305
if (change !== undefined) {
@@ -344,7 +349,7 @@ function addToSelection(
344349

345350
// Get the ValueEntry objects for the facts that match our selector
346351
function getMatchingFacts<Space extends MemorySpace>(
347-
session: Session<Space>,
352+
session: SpaceStoreSession<Space>,
348353
factSelector: FactSelector,
349354
): Iterable<IAttestation & { cause: CauseString; since: number }> {
350355
const results = [];

0 commit comments

Comments
 (0)