Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): env variable to control slow threshold of token factory #13799

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/core/injector/module-token-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { performance } from 'perf_hooks';
const CLASS_STR = 'class ';
const CLASS_STR_LEN = CLASS_STR.length;

const slowThresholdMs = Number(
+process.env.NEST_TOKEN_FACTORY_SLOW_THRESHOLD_MS || 10,
);

export class ModuleTokenFactory {
private readonly moduleTokenCache = new Map<string, string>();
private readonly moduleIdsCache = new WeakMap<Type<unknown>, string>();
Expand All @@ -34,10 +38,10 @@ export class ModuleTokenFactory {
const opaqueTokenString = this.getStringifiedOpaqueToken(opaqueToken);
const timeSpentInMs = performance.now() - start;

if (timeSpentInMs > 10) {
if (timeSpentInMs > slowThresholdMs) {
const formattedTimeSpent = timeSpentInMs.toFixed(2);
this.logger.warn(
`The module "${opaqueToken.module}" is taking ${formattedTimeSpent}ms to serialize, this may be caused by larger objects statically assigned to the module. More details: https://github.com/nestjs/nest/issues/12738`,
`The module "${opaqueToken.module}" is taking ${formattedTimeSpent}ms to serialize, this may be caused by larger objects statically assigned to the module. To ignore, increase the threshold using env variable NEST_TOKEN_FACTORY_SLOW_THRESHOLD_MS. More details: https://github.com/nestjs/nest/issues/12738`,
);
}

Expand Down
Loading