Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "perf: skip eval cache for __mkPreval entry-point evaluations",
"packageName": "@griffel/transform",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
8 changes: 5 additions & 3 deletions packages/transform/src/evaluation/module.mts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class Module {
},
);

evaluate(text: string, only: string[] | null = null): void {
evaluate(text: string, only: string[] | null = null, useEvalCache = true): void {
const { filename } = this;
// Find last matching rule (iterate backwards, break on first match)
let action: EvalRule['action'] = 'ignore';
Expand All @@ -184,7 +184,7 @@ export class Module {

const cacheKey = [this.filename, ...(only ?? [])];

if (EvalCache.has(cacheKey, text)) {
if (useEvalCache && EvalCache.has(cacheKey, text)) {
this.exports = EvalCache.get(cacheKey, text);
return;
}
Expand Down Expand Up @@ -234,7 +234,9 @@ export class Module {
}),
);

EvalCache.set(cacheKey, text, this.exports);
if (useEvalCache) {
EvalCache.set(cacheKey, text, this.exports);
}
}

static invalidate = (): void => {
Expand Down
4 changes: 3 additions & 1 deletion packages/transform/src/evaluation/vmEvaluator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export const __mkPreval = (() => {

try {
const mod = new Module(filename, evaluationRules, resolveFilename);
mod.evaluate(codeForEvaluation, ['__mkPreval']);
// useEvalCache=false: each source file produces unique codeForEvaluation (different sourceCode +
// expressionCode), so the eval cache would never hit — skip the unnecessary hashing and map storage.
mod.evaluate(codeForEvaluation, ['__mkPreval'], /* useEvalCache */ false);

const result = (mod.exports as { __mkPreval: unknown }).__mkPreval;

Expand Down
Loading