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

Nestjs warns about "TypeOrmModule" taking a long time to serialize #1873

Closed
1 of 4 tasks
hfhchan-plb opened this issue Jan 23, 2024 · 8 comments
Closed
1 of 4 tasks

Comments

@hfhchan-plb
Copy link

hfhchan-plb commented Jan 23, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

An error gets logged to the logs:

The module "TypeOrmModule" is taking 10.88ms 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 "TypeOrmModule" is taking 20.62ms to serialize, this may be caused by larger objects statically assigned to the module. More details: https://github.com/nestjs/nest/issues/12738

Minimum reproduction code


@Module({
  imports: [
    TypeOrmModule.forRootAsync({
      inject: [],
      name: DBConnection.PG,
      useFactory: (): TypeOrmModuleOptions => ({
        name: DBConnection.PG,
        type: 'postgres',
        host: /* redacted */,
        port: /* redacted */,
        username: /* redacted */,
        password: /* redacted */,
        database: /* redacted */,
        entities:/* array of a ton of entities */,
        keepConnectionAlive: true,
        logger: /* redacted large object */
        ssl: {
          ca: /* huge string */,
        },
        applicationName: getApplicationName(),
        uuidExtension: 'pgcrypto',
        installExtensions: false,
      }),
    }),
  ],
})
export class EntityModule {}

Steps to reproduce

No response

Expected behavior

No error

Package version

10.0.1

NestJS version

10.3.0

Node.js version

No response

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@micalevisk
Copy link
Member

micalevisk commented Jan 23, 2024

so what's the issue here?

make sure you're using the latest version of @nestjs/core and @nestjs/common

@hfhchan-plb
Copy link
Author

Sorry I've just updated the minimum reproduction code.

I'm using 10.3.0 which appears to be the latest version.

@micalevisk
Copy link
Member

ok but what's the expected behavior?

that's just an warning message, not an error, right? You can see why it exists in the issue nestjs/nest#12738

@hfhchan-plb
Copy link
Author

I think the expected behavior would be that the TypeORM integration would avoid having a large amount of static data to be serialized?

I would like to find a way to remove that 30 ms extra time per cold start 🤔

@hfhchan-plb hfhchan-plb changed the title Nestjs throws error about "TypeOrmModule" taking a long time to serialize Nestjs warns about "TypeOrmModule" taking a long time to serialize Jan 23, 2024
@micalevisk
Copy link
Member

micalevisk commented Jan 23, 2024

I believe that this is a limitation that we cannot circumvent on the nestjs side yet

@hfhchan-plb
Copy link
Author

This can probably be fixed by replacing the useValue with useFactory like the original issue

@micalevisk
Copy link
Member

micalevisk commented Jan 23, 2024

so please try it out changing the js code of your node_modules/@nestjs/typeorm dir

@hfhchan-plb
Copy link
Author

Running this locally I'm seeing 0.06 ms - 0.19 ms without the change and 0.07 ms - 0.13 ms with the change with some spikes going up to 1 ms or 2 ms. As I'm using forRootAsync() the only thing being serialized is generateString(), which basically just calls uuid. So it looks like the runtime itself was stalling to produce random values 🤷

Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants