-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(@angular-devkit/build-angular): cache Sass in memory with esbuil…
…d watch mode To improve rebuild performance when using Sass stylesheets with the esbuild-based browser application builder in watch mode, Sass stylesheets that are not affected by any file changes will now be cached and directly reused. This avoids performing potentially expensive Sass preprocessing on stylesheets that will not change within a rebuild. (cherry picked from commit 1e78cf9)
- Loading branch information
Showing
6 changed files
with
122 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/angular_devkit/build_angular/src/builders/browser-esbuild/load-result-cache.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import type { OnLoadResult } from 'esbuild'; | ||
|
||
export interface LoadResultCache { | ||
get(path: string): OnLoadResult | undefined; | ||
put(path: string, result: OnLoadResult): Promise<void>; | ||
} | ||
|
||
export class MemoryLoadResultCache implements LoadResultCache { | ||
#loadResults = new Map<string, OnLoadResult>(); | ||
#fileDependencies = new Map<string, Set<string>>(); | ||
|
||
get(path: string): OnLoadResult | undefined { | ||
return this.#loadResults.get(path); | ||
} | ||
|
||
async put(path: string, result: OnLoadResult): Promise<void> { | ||
this.#loadResults.set(path, result); | ||
if (result.watchFiles) { | ||
for (const watchFile of result.watchFiles) { | ||
let affected = this.#fileDependencies.get(watchFile); | ||
if (affected === undefined) { | ||
affected = new Set(); | ||
this.#fileDependencies.set(watchFile, affected); | ||
} | ||
affected.add(path); | ||
} | ||
} | ||
} | ||
|
||
invalidate(path: string): boolean { | ||
const affected = this.#fileDependencies.get(path); | ||
let found = false; | ||
|
||
if (affected) { | ||
affected.forEach((a) => (found ||= this.#loadResults.delete(a))); | ||
this.#fileDependencies.delete(path); | ||
} | ||
|
||
found ||= this.#loadResults.delete(path); | ||
|
||
return found; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters