Skip to content

Commit 82b09c3

Browse files
hardfistchenjiahan
andauthored
perf: disable js tracing in non-profile mode (#9046)
* perf: disable js tracing in non-profile mode * chore: fix type * chore: fix type again * chore: fix type * Update packages/rspack-tracing/types/package.json --------- Co-authored-by: neverland <[email protected]>
1 parent 1d58294 commit 82b09c3

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

packages/rspack-tracing/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Tracing Utility for Rspack
2+
3+
> Rspack's internal tracing tools, don't use it directly in your project, it may contain breaking change in minor & patch release right now.

packages/rspack-tracing/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"license": "MIT",
1818
"main": "./index.js",
19-
"types": "./index.d.ts",
19+
"types": "./types/index.d.ts",
2020
"scripts": {
2121
"build": "tsc -b ./tsconfig.build.json"
2222
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export function initOpenTelemetry(): Promise<void>;
22
export function shutdownOpenTelemetry(): Promise<void>;
33
export { trace, propagation, context } from "@opentelemetry/api";
4+
export type { Tracer, Context } from "@opentelemetry/api";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"//": "This file is for making TypeScript work with moduleResolution node16+.",
3+
"version": "0.0.0"
4+
}

packages/rspack/src/loader-runner/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
SourceMapSource
2727
} from "webpack-sources";
2828

29+
import type { Context, Tracer } from "@rspack/tracing";
2930
import type { Compilation } from "../Compilation";
3031
import type { Compiler } from "../Compiler";
3132
import { Module } from "../Module";
@@ -339,8 +340,12 @@ function getCurrentLoader(
339340
}
340341
return null;
341342
}
342-
343+
let tracingCache!: { tracer?: Tracer; activeContext?: Context };
343344
async function tryTrace(context: JsLoaderContext) {
345+
// disable tracing in non-profile mode
346+
if (!process.env.RSPACK_PROFILE) {
347+
return {};
348+
}
344349
try {
345350
const {
346351
trace,
@@ -352,9 +357,11 @@ async function tryTrace(context: JsLoaderContext) {
352357
tracingContext.active(),
353358
context.__internal__tracingCarrier
354359
);
355-
return { tracer, activeContext };
360+
tracingCache = { tracer, activeContext };
361+
return tracingCache;
356362
} catch (error) {
357-
return { tracer: null, activeContext: null };
363+
tracingCache = {};
364+
return tracingCache;
358365
}
359366
}
360367

0 commit comments

Comments
 (0)