-
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/build): add persistent caching of JavaScript transforma…
…tions When caching is enabled for the Angular CLI, the JavaScript transformer within the application build system will now perform persistent caching of its output. This allows for improved warm build times by removing the need to run the Angular linker and build optimizer steps against unchanged third-party code within each build. This does not affect hot rebuilds that would take place during watch mode since the outputs are already cached within memory. The on-disk storage of the cached data is handled by the `lmdb` package which provides fast key/value storage and built-in off-thread compression. This package is currently used by such projects as Gatsby and parcel for their respective caching subsystems. Warm production build of a new 18.0.0-rc.2 project with disabled caching: ``` Application bundle generation complete. [3.698 seconds] ``` With enabled caching: ``` Application bundle generation complete. [2.277 seconds] ```
- Loading branch information
1 parent
9ce8fef
commit 09e5796
Showing
7 changed files
with
208 additions
and
5 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
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
59 changes: 59 additions & 0 deletions
59
packages/angular/build/src/tools/esbuild/lmdb-cache-store.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,59 @@ | ||
/** | ||
* @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 { RootDatabase, open } from 'lmdb'; | ||
import { Cache, CacheStore } from './cache'; | ||
|
||
export class LmbdCacheStore implements CacheStore<unknown> { | ||
readonly #cacheFileUrl; | ||
#db: RootDatabase | undefined; | ||
|
||
constructor(readonly cachePath: string) { | ||
this.#cacheFileUrl = cachePath; | ||
} | ||
|
||
#ensureCacheFile(): RootDatabase { | ||
this.#db ??= open({ | ||
path: this.#cacheFileUrl, | ||
compression: true, | ||
}); | ||
|
||
return this.#db; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
async get(key: string): Promise<any> { | ||
const db = this.#ensureCacheFile(); | ||
const value = db.get(key); | ||
|
||
return value; | ||
} | ||
|
||
has(key: string): boolean { | ||
return this.#ensureCacheFile().doesExist(key); | ||
} | ||
|
||
async set(key: string, value: unknown): Promise<this> { | ||
const db = this.#ensureCacheFile(); | ||
await db.put(key, value); | ||
|
||
return this; | ||
} | ||
|
||
createCache<V = unknown>(namespace: string): Cache<V> { | ||
return new Cache(this, namespace); | ||
} | ||
|
||
async close() { | ||
try { | ||
await this.#db?.close(); | ||
} catch { | ||
// Failure to close should not be fatal | ||
} | ||
} | ||
} |
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