Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache type model #193

Merged
merged 4 commits into from
Dec 11, 2023
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
57 changes: 25 additions & 32 deletions libraries/analysis-javascript/lib/type/resolving/TypeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,19 @@ export class TypeModel {
randomTypeProbability: number,
id: string
): string {
const probabilities = this.calculateProbabilitiesForElement(
incorporateExecutionScore,
id
);

// const x = new Map();
// for (const [type, probability] of probabilities.entries()) {
// const typeEnum = type.includes("<>") ? type.split("<>")[1] : type;

// if (!x.has(typeEnum)) {
// x.set(typeEnum, 0);
// }
let probabilities;

// x.set(typeEnum, x.get(typeEnum) + probability);
// }
// console.log(id);
// console.log(x);
// 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)
if (this._scoreHasChangedMap.get(id)) {
probabilities = this.calculateProbabilitiesForElement(
incorporateExecutionScore,
id
);
this._scoreHasChangedMap.set(id, false);
} else {
// prevent recalculation of probabilities without score changes
probabilities = this._elementTypeProbabilityMap.get(id);
}

const genericTypes = [
TypeEnum.ARRAY,
Expand Down Expand Up @@ -357,10 +353,19 @@ export class TypeModel {
randomTypeProbability: number,
id: string
): string {
const probabilities = this.calculateProbabilitiesForElement(
incorporateExecutionScore,
id
);
let probabilities;

// 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)
if (this._scoreHasChangedMap.get(id)) {
probabilities = this.calculateProbabilitiesForElement(
incorporateExecutionScore,
id
);
this._scoreHasChangedMap.set(id, false);
} else {
// prevent recalculation of probabilities without score changes
probabilities = this._elementTypeProbabilityMap.get(id);
}

const genericTypes = [
TypeEnum.ARRAY,
Expand Down Expand Up @@ -421,16 +426,6 @@ export class TypeModel {
id: string,
relationPairsVisited?: Map<string, Set<string>>
): Map<string, number> {
// if (!this._scoreHasChangedMap.has(element)) {
// throw new ImplementationError(`Element ${element} does not exist`);
// }
// if (this._scoreHasChangedMap.get(element) === false) {
// // prevent recalculation of probabilities without score changes
// return this._elementTypeProbabilityMap.get(element);
// }

// this._scoreHasChangedMap.set(element, false);

let probabilityMap = new Map<string, number>();

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

if (!relationPairsVisited) {
relationPairsVisited = new Map();
// this._scoreHasChangedMap.set(element, false);
// this._elementTypeProbabilityMap.set(element, probabilityMap);
}

let totalScore = this._sum(typeScoreMap.values());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ export class JavaScriptRandomSampler extends JavaScriptTestCaseSampler {
this.randomTypeProbability,
id
);

break;
}
case "ranked": {
Expand Down
Loading