Skip to content

Commit 9e35050

Browse files
committed
AEDebugging_ Optimize triplet search
SQUASHED: AUTO-COMMIT-src-client-reactive-active-expression-rewriting-active-expression-rewriting.js,AUTO-COMMIT-src-client-reactive-active-expression-rewriting-bidirectional-multi-map.js,AUTO-COMMIT-src-client-reactive-babel-plugin-polymorphic-identifiers-polymorphic-identifiers.js,
1 parent e0ca6fb commit 9e35050

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

src/client/reactive/active-expression-rewriting/active-expression-rewriting.js

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -216,33 +216,35 @@ class Dependency {
216216

217217
const DependenciesToAExprs = {
218218
_depsToAExprs: new BidirectionalMultiMap(),
219+
_AEsPerFile: new Map(),
219220

220221
associate(dep, aexpr) {
222+
const location = aexpr.meta().get("location").file;
223+
if(!this._AEsPerFile.has(location)) {
224+
this._AEsPerFile.set(location, new Set());
225+
}
226+
this._AEsPerFile.get(location).add(aexpr);
221227
this._depsToAExprs.associate(dep, aexpr);
222228
dep.updateTracking();
223229
debouncedUpdateDebuggingViews();
224230
},
225231

226232
disconnectAllForAExpr(aexpr) {
233+
const location = aexpr.meta().get("location").file;
234+
if(this._AEsPerFile.has(location)) {
235+
this._AEsPerFile.get(location).delete(aexpr);
236+
}
227237
const deps = this.getDepsForAExpr(aexpr);
228238
this._depsToAExprs.removeAllLeftFor(aexpr);
229239
deps.forEach(dep => dep.updateTracking());
230240
debouncedUpdateDebuggingViews();
231241
},
232242

233-
getAETriplesForFile(url) {
234-
const result = [];
235-
for (const ae of this._depsToAExprs.getAllRight()) {
236-
const location = ae.meta().get("location").file;
237-
if (location.includes(url)) {
238-
for (const dependency of this.getDepsForAExpr(ae)) {
239-
for (const hook of HooksToDependencies.getHooksForDep(dependency)) {
240-
result.push({ hook, dependency, ae });
241-
}
242-
}
243-
}
243+
getAEsInFile(url) {
244+
for(const [location, aes] of this._AEsPerFile.entries()) {
245+
if(location.includes(url)) return aes;
244246
}
245-
return result;
247+
return [];
246248
},
247249

248250
getAExprsForDep(dep) {
@@ -275,24 +277,20 @@ const HooksToDependencies = {
275277
this._hooksToDeps.associate(hook, dep);
276278
debouncedUpdateDebuggingViews();
277279
},
280+
278281
remove(hook, dep) {
279282
this._hooksToDeps.remove(hook, dep);
280283
debouncedUpdateDebuggingViews();
281284
},
282285

283-
async getHookTriplesForFile(url) {
284-
const result = [];
285-
for (const hook of this._hooksToDeps.getAllLeft()) {
286-
const locations = await hook.getLocations();
287-
if (locations.some(loc => loc && loc.source.includes(url))) {
288-
for (const dependency of this.getDepsForHook(hook)) {
289-
for (const ae of DependenciesToAExprs.getAExprsForDep(dependency)) {
290-
result.push({ hook, dependency, ae });
291-
}
292-
}
293-
}
294-
}
295-
return result;
286+
async getHooksInFile(url) {
287+
const hooksWithLocations = await Promise.all(this._hooksToDeps.getAllLeft().map(hook => {
288+
return hook.getLocations().then(locations => {return {hook, locations}});
289+
}))
290+
return hooksWithLocations.filter(({hook, locations}) => {
291+
const location = locations.find(loc => loc && loc.source);
292+
return location && locations.source.includes(url);
293+
}).map(({hook, locations}) => hook);
296294
},
297295

298296
disconnectAllForDependency(dep) {
@@ -932,12 +930,19 @@ export async function registerFileForAEDebugging(url, context, triplesCallback)
932930

933931
export async function getDependencyTriplesForFile(url) {
934932
const result = [];
935-
for (const hook of HooksToDependencies._hooksToDeps.getAllLeft()) {
936-
const locations = await hook.getLocations();
933+
for (const ae of DependenciesToAExprs.getAEsInFile(url)) {
934+
for (const dependency of DependenciesToAExprs.getDepsForAExpr(ae)) {
935+
for(const hook of HooksToDependencies.getHooksForDep(dependency)) {
936+
result.push({ hook, dependency, ae });
937+
}
938+
}
939+
}
940+
for (const hook of await HooksToDependencies.getHooksInFile(url)) {
937941
for (const dependency of HooksToDependencies.getDepsForHook(hook)) {
938-
for (const ae of DependenciesToAExprs.getAExprsForDep(dependency)) {
942+
for(const ae of DependenciesToAExprs.getAExprsForDep(dependency)) {
939943
const location = ae.meta().get("location").file;
940-
if (location.includes(url) || locations.some(loc => loc && loc.file.includes(url))) {
944+
// if the AE is also in this file, we already covered it with the previous loop
945+
if (!location.includes(url)){
941946
result.push({ hook, dependency, ae });
942947
}
943948
}

src/client/reactive/active-expression-rewriting/bidirectional-multi-map.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ export default class BidirectionalMultiMap {
2727
this.domainToRange.clear();
2828
this.rangeToDomain.clear();
2929
}
30+
31+
hasRight(val) {
32+
return this.rangeToDomain.has(val);
33+
}
34+
35+
hasLeft(val) {
36+
return this.domainToRange.has(val);
37+
}
3038

3139
getRightsFor(left) {
3240
return this.domainToRange.getOrCreate(left, () => new Set());

src/client/reactive/babel-plugin-polymorphic-identifiers/polymorphic-identifiers.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export default function ({ types: t, template }) {
3030
return foundDirective;
3131
}
3232

33-
debugger
3433
const shouldTransform = state.opts.executedIn === 'workspace' || hasDirective(path, "pi");
3534
if (!shouldTransform) {
3635
return;

0 commit comments

Comments
 (0)