Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5174f1b

Browse files
feat: cache type model (#193)
1 parent 4afd4ed commit 5174f1b

File tree

3 files changed

+473
-529
lines changed

3 files changed

+473
-529
lines changed

‎libraries/analysis-javascript/lib/type/resolving/TypeModel.ts

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -289,23 +289,19 @@ export class TypeModel {
289289
randomTypeProbability: number,
290290
id: string
291291
): string {
292-
const probabilities = this.calculateProbabilitiesForElement(
293-
incorporateExecutionScore,
294-
id
295-
);
296-
297-
// const x = new Map();
298-
// for (const [type, probability] of probabilities.entries()) {
299-
// const typeEnum = type.includes("<>") ? type.split("<>")[1] : type;
300-
301-
// if (!x.has(typeEnum)) {
302-
// x.set(typeEnum, 0);
303-
// }
292+
let probabilities;
304293

305-
// x.set(typeEnum, x.get(typeEnum) + probability);
306-
// }
307-
// console.log(id);
308-
// console.log(x);
294+
// This allows caching of type scores. The only problem is that when a score of a relation changes it will not recalculate for the current element (only for the relation element)
295+
if (this._scoreHasChangedMap.get(id)) {
296+
probabilities = this.calculateProbabilitiesForElement(
297+
incorporateExecutionScore,
298+
id
299+
);
300+
this._scoreHasChangedMap.set(id, false);
301+
} else {
302+
// prevent recalculation of probabilities without score changes
303+
probabilities = this._elementTypeProbabilityMap.get(id);
304+
}
309305

310306
const genericTypes = [
311307
TypeEnum.ARRAY,
@@ -357,10 +353,19 @@ export class TypeModel {
357353
randomTypeProbability: number,
358354
id: string
359355
): string {
360-
const probabilities = this.calculateProbabilitiesForElement(
361-
incorporateExecutionScore,
362-
id
363-
);
356+
let probabilities;
357+
358+
// This allows caching of type scores. The only problem is that when a score of a relation changes it will not recalculate for the current element (only for the relation element)
359+
if (this._scoreHasChangedMap.get(id)) {
360+
probabilities = this.calculateProbabilitiesForElement(
361+
incorporateExecutionScore,
362+
id
363+
);
364+
this._scoreHasChangedMap.set(id, false);
365+
} else {
366+
// prevent recalculation of probabilities without score changes
367+
probabilities = this._elementTypeProbabilityMap.get(id);
368+
}
364369

365370
const genericTypes = [
366371
TypeEnum.ARRAY,
@@ -421,16 +426,6 @@ export class TypeModel {
421426
id: string,
422427
relationPairsVisited?: Map<string, Set<string>>
423428
): Map<string, number> {
424-
// if (!this._scoreHasChangedMap.has(element)) {
425-
// throw new ImplementationError(`Element ${element} does not exist`);
426-
// }
427-
// if (this._scoreHasChangedMap.get(element) === false) {
428-
// // prevent recalculation of probabilities without score changes
429-
// return this._elementTypeProbabilityMap.get(element);
430-
// }
431-
432-
// this._scoreHasChangedMap.set(element, false);
433-
434429
let probabilityMap = new Map<string, number>();
435430

436431
if (id === "anon") {
@@ -446,8 +441,6 @@ export class TypeModel {
446441

447442
if (!relationPairsVisited) {
448443
relationPairsVisited = new Map();
449-
// this._scoreHasChangedMap.set(element, false);
450-
// this._elementTypeProbabilityMap.set(element, probabilityMap);
451444
}
452445

453446
let totalScore = this._sum(typeScoreMap.values());

‎libraries/search-javascript/lib/testcase/sampling/JavaScriptRandomSampler.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ export class JavaScriptRandomSampler extends JavaScriptTestCaseSampler {
548548
this.randomTypeProbability,
549549
id
550550
);
551-
552551
break;
553552
}
554553
case "ranked": {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /