Skip to content

Commit

Permalink
perf: optimize JS communication with lazy getters (#7163)
Browse files Browse the repository at this point in the history
* perf: use Reference to share JsStatsModule js instance

* fix: ts type error

* feat: use generate_getters macros

* fix: use generate_getters macros for JsStatsChunk

* refactor: rename getters macros name

* refactor: move fn out struct

* feat: lazy JsStatsModuleReason

* refactor: remove Reference for JsStatsModule

* refactor: impl TryFrom for JsStatsModule and JsStatsChunk

* chore: update api.md
  • Loading branch information
SyMind authored Jul 17, 2024
1 parent f1ff9fe commit 2fe5430
Show file tree
Hide file tree
Showing 9 changed files with 375 additions and 225 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

148 changes: 74 additions & 74 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,80 @@ export class JsStats {
getHash(): string | null
}

export class JsStatsChunk {
get type(): string
get files(): Array<string>
get auxiliaryFiles(): Array<string>
get id(): string | undefined
get idHints(): Array<string>
get hash(): string | undefined
get entry(): boolean
get initial(): boolean
get names(): Array<string>
get size(): number
get parents(): Array<string> | undefined
get children(): Array<string> | undefined
get siblings(): Array<string> | undefined
get childrenByOrder(): Record<string, Array<string>>
get runtime(): Array<string>
get reason(): string | undefined
get rendered(): boolean
get sizes(): Array<JsStatsSize>
get origins(): Array<JsOriginRecord>
get modules(): Array<JsStatsModule> | undefined
}

export class JsStatsModule {
get type(): string
get moduleType(): string
get identifier(): string
get name(): string
get id(): string | undefined
get chunks(): Array<string | undefined | null>
get size(): number
get depth(): number | undefined
get dependent(): boolean | undefined
get issuer(): string | undefined
get issuerName(): string | undefined
get issuerId(): string | undefined
get nameForCondition(): string | undefined
get assets(): Array<string> | undefined
get source(): string | Buffer | undefined
get orphan(): boolean
get providedExports(): Array<string> | undefined
get usedExports(): string | Array<string> | undefined
get optimizationBailout(): Array<string> | undefined
get preOrderIndex(): number | undefined
get postOrderIndex(): number | undefined
get built(): boolean
get codeGenerated(): boolean
get buildTimeExecuted(): boolean
get cached(): boolean
get cacheable(): boolean
get optional(): boolean
get failed(): boolean
get errors(): number
get warnings(): number
get sizes(): Array<JsStatsSize>
get issuerPath(): Array<JsStatsModuleIssuer>
get profile(): JsStatsModuleProfile | undefined
get reasons(): Array<JsStatsModuleReason> | undefined
get modules(): Array<JsStatsModule> | undefined
}

export class JsStatsModuleReason {
get moduleIdentifier(): string | undefined
get moduleName(): string | undefined
get moduleId(): string | undefined
get type(): string | undefined
get userRequest(): string | undefined
}

export class JsStatsSize {
sourceType: string
size: number
}

export class Rspack {
constructor(options: RawOptions, builtinPlugins: Array<BuiltinPlugin>, registerJsTaps: RegisterJsTaps, outputFilesystem: ThreadsafeNodeFS, resolverFactoryReference: JsResolverFactory)
setNonSkippableRegisters(kinds: Array<RegisterJsTapKind>): void
Expand Down Expand Up @@ -546,29 +620,6 @@ export interface JsStatsAssetsByChunkName {
files: Array<string>
}

export interface JsStatsChunk {
type: string
files: Array<string>
auxiliaryFiles: Array<string>
id?: string
idHints: Array<string>
hash?: string
entry: boolean
initial: boolean
names: Array<string>
size: number
modules?: Array<JsStatsModule>
parents?: Array<string>
children?: Array<string>
siblings?: Array<string>
childrenByOrder: Record<string, Array<string>>
runtime: Array<string>
sizes: Array<JsStatsSize>
reason?: string
rendered: boolean
origins: Array<JsOriginRecord>
}

export interface JsStatsChunkGroup {
name: string
chunks: Array<string | undefined | null>
Expand Down Expand Up @@ -621,44 +672,6 @@ export interface JsStatsMillisecond {
subsecMillis: number
}

export interface JsStatsModule {
type: string
moduleType: string
identifier: string
name: string
id?: string
chunks: Array<string | undefined | null>
size: number
sizes: Array<JsStatsSize>
depth?: number
dependent?: boolean
issuer?: string
issuerName?: string
issuerId?: string
issuerPath: Array<JsStatsModuleIssuer>
modules?: Array<JsStatsModule>
nameForCondition?: string
reasons?: Array<JsStatsModuleReason>
assets?: Array<string>
source?: string | Buffer
profile?: JsStatsModuleProfile
orphan: boolean
providedExports?: Array<string>
usedExports?: string | Array<string>
optimizationBailout?: Array<string>
preOrderIndex?: number
postOrderIndex?: number
built: boolean
codeGenerated: boolean
buildTimeExecuted: boolean
cached: boolean
cacheable: boolean
optional: boolean
failed: boolean
errors: number
warnings: number
}

export interface JsStatsModuleIssuer {
identifier: string
name: string
Expand All @@ -670,14 +683,6 @@ export interface JsStatsModuleProfile {
building: JsStatsMillisecond
}

export interface JsStatsModuleReason {
moduleIdentifier?: string
moduleName?: string
moduleId?: string
type?: string
userRequest?: string
}

export interface JsStatsModuleTrace {
origin: JsStatsModuleTraceModule
module: JsStatsModuleTraceModule
Expand All @@ -693,11 +698,6 @@ export interface JsStatsOptimizationBailout {
inner: string
}

export interface JsStatsSize {
sourceType: string
size: number
}

export interface JsStatsWarning {
message: string
chunkName?: string
Expand Down
25 changes: 13 additions & 12 deletions crates/rspack_binding_values/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ repository = "https://github.com/web-infra-dev/rspack"
version = "0.1.0"

[dependencies]
futures = { workspace = true }
heck = { workspace = true }
napi = { workspace = true, features = ["async", "tokio_rt", "serde-json", "anyhow"] }
napi-derive = { workspace = true }
once_cell = { workspace = true }
rspack_core = { path = "../rspack_core" }
rspack_error = { path = "../rspack_error" }
rspack_napi = { path = "../rspack_napi" }
rspack_regex = { path = "../rspack_regex" }
rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
futures = { workspace = true }
heck = { workspace = true }
napi = { workspace = true, features = ["async", "tokio_rt", "serde-json", "anyhow"] }
napi-derive = { workspace = true }
once_cell = { workspace = true }
rspack_core = { path = "../rspack_core" }
rspack_error = { path = "../rspack_error" }
rspack_macros = { path = "../rspack_macros" }
rspack_napi = { path = "../rspack_napi" }
rspack_regex = { path = "../rspack_regex" }
rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Loading

2 comments on commit 2fe5430

@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-17 58e6453) Current Change
10000_development-mode + exec 2.25 s ± 29 ms 2.23 s ± 17 ms -0.70 %
10000_development-mode_hmr + exec 700 ms ± 3.6 ms 700 ms ± 7.2 ms +0.04 %
10000_production-mode + exec 2.88 s ± 22 ms 2.81 s ± 16 ms -2.20 %
arco-pro_development-mode + exec 1.91 s ± 80 ms 1.89 s ± 52 ms -0.93 %
arco-pro_development-mode_hmr + exec 435 ms ± 3.8 ms 435 ms ± 3.9 ms +0.08 %
arco-pro_production-mode + exec 3.48 s ± 80 ms 3.47 s ± 95 ms -0.34 %
threejs_development-mode_10x + exec 1.77 s ± 19 ms 1.77 s ± 18 ms -0.42 %
threejs_development-mode_10x_hmr + exec 882 ms ± 8.8 ms 868 ms ± 5.3 ms -1.61 %
threejs_production-mode_10x + exec 5.78 s ± 29 ms 5.75 s ± 43 ms -0.52 %

@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 ✅ success
_selftest ✅ success
nx ✅ success
rspress ✅ success
rsbuild ✅ success
examples ✅ success

Please sign in to comment.