Performance: Why modules organize application structure
MEDIUM IMPACT
Modules affect initial load time and runtime performance by controlling how code is split and loaded in the application.
import { Module } from '@nestjs/common'; @Module({ imports: [FeatureAModule, FeatureBModule] }) export class AppModule {} @Module({ providers: [FeatureAService], exports: [FeatureAService] }) export class FeatureAModule {} @Module({ providers: [FeatureBService], exports: [FeatureBService] }) export class FeatureBModule {}
import { FeatureAService } from './feature-a.service'; import { FeatureBService } from './feature-b.service'; import { Module } from '@nestjs/common'; @Module({ providers: [FeatureAService, FeatureBService], exports: [FeatureAService, FeatureBService] }) export class AppModule {}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Monolithic module loading | N/A | N/A | High initial script parsing and execution | [X] Bad |
| Feature modules with lazy loading | N/A | N/A | Lower initial script parsing and execution | [OK] Good |