Skip to content

Commit

Permalink
perf: cache compilation.entrypoints (#7059)
Browse files Browse the repository at this point in the history
perf: cache
  • Loading branch information
chenjiahan authored Jul 8, 2024
1 parent ef804bf commit 03e0488
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/rspack/src/Compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { Stats, StatsAsset, StatsError, StatsModule } from "./Stats";
import { LogType, Logger } from "./logging/Logger";
import { StatsFactory } from "./stats/StatsFactory";
import { StatsPrinter } from "./stats/StatsPrinter";
import { concatErrorMsgAndStack } from "./util";
import { type AssetInfo, JsAssetInfo } from "./util/AssetInfo";
import MergeCaller from "./util/MergeCaller";
import { createFakeCompilationDependencies } from "./util/fake";
Expand Down Expand Up @@ -142,7 +141,8 @@ export type NormalizedStatsOptions = KnownNormalizedStatsOptions &

export class Compilation {
#inner: JsCompilation;
#cachedAssets: Record<string, Source>;
#cachedAssets?: Record<string, Source>;
#cachedEntrypoints?: ReadonlyMap<string, Entrypoint>;

hooks: Readonly<{
processAssets: liteTapable.AsyncSeriesHook<Assets>;
Expand Down Expand Up @@ -224,7 +224,6 @@ export class Compilation {

constructor(compiler: Compiler, inner: JsCompilation) {
this.#inner = inner;
this.#cachedAssets = this.#createCachedAssets();
this.#customModules = {};

const processAssetsHook = new liteTapable.AsyncSeriesHook<Assets>([
Expand Down Expand Up @@ -342,19 +341,25 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
* Get a map of all assets.
*/
get assets(): Record<string, Source> {
if (!this.#cachedAssets) {
this.#cachedAssets = this.#createCachedAssets();
}
return this.#cachedAssets;
}

/**
* Get a map of all entrypoints.
*/
get entrypoints(): ReadonlyMap<string, Entrypoint> {
return new Map(
Object.entries(this.#inner.entrypoints).map(([n, e]) => [
n,
Entrypoint.__from_binding(e, this.#inner)
])
);
if (!this.#cachedEntrypoints) {
this.#cachedEntrypoints = new Map(
Object.entries(this.#inner.entrypoints).map(([n, e]) => [
n,
Entrypoint.__from_binding(e, this.#inner)
])
);
}
return this.#cachedEntrypoints;
}

get modules(): ReadonlySet<Module> {
Expand Down

2 comments on commit 03e0488

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
_selftest ✅ success
nx ✅ success
rspress ✅ success
rsbuild ✅ success
examples ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-07-08 d14720d) Current Change
10000_development-mode + exec 2.16 s ± 25 ms 2.15 s ± 22 ms -0.49 %
10000_development-mode_hmr + exec 692 ms ± 2.9 ms 692 ms ± 4.1 ms -0.06 %
10000_production-mode + exec 2.73 s ± 23 ms 2.79 s ± 22 ms +2.17 %
arco-pro_development-mode + exec 1.91 s ± 87 ms 1.85 s ± 50 ms -2.79 %
arco-pro_development-mode_hmr + exec 435 ms ± 3.2 ms 434 ms ± 2.4 ms -0.24 %
arco-pro_production-mode + exec 3.42 s ± 95 ms 3.44 s ± 103 ms +0.40 %
threejs_development-mode_10x + exec 1.58 s ± 19 ms 1.6 s ± 14 ms +1.62 %
threejs_development-mode_10x_hmr + exec 798 ms ± 6.9 ms 826 ms ± 10 ms +3.51 %
threejs_production-mode_10x + exec 5.58 s ± 29 ms 5.62 s ± 43 ms +0.81 %

Please sign in to comment.