Performance: Feature modules
MEDIUM IMPACT
Feature modules affect the initial load time and memory usage by organizing code into lazy-loadable chunks.
import { Module } from '@nestjs/common'; import { UsersService } from './users.service'; import { UsersController } from './users.controller'; @Module({ providers: [UsersService], controllers: [UsersController], exports: [UsersService], }) export class UsersModule {} // Then lazy load UsersModule using dynamic imports or module federation
import { Module } from '@nestjs/common'; import { UsersService } from './users.service'; import { UsersController } from './users.controller'; @Module({ providers: [UsersService], controllers: [UsersController], exports: [UsersService], }) export class UsersModule {} // Then import UsersModule directly in AppModule eagerly
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Eagerly loading all feature modules | N/A | N/A | High initial paint delay | [X] Bad |
| Lazy loading feature modules on demand | N/A | N/A | Faster initial paint | [OK] Good |