Skip to content

Adopt dynamic-imports for node module #30685

@jrieken

Description

@jrieken

With TypeScript 2.4 we can now use dynamic imports to improve startup performance. The idea is to lazy load certain modules that aren't (always) needed for starting up. Generally, lazy loading requires some amd-bundle-gymnastics but with node-modules everything is easy. The motivation is that 20% of code loading (from cached data) is spend loading node-modules.

To see how long it takes to load a certain module do the following:

  • start code with the --performance flag
  • in code hit F1 and show startup performance
  • below the table with startup times are different sections outlining times to load and execute all modules we have. Look at everything taking 10ms or longer

In short, the idea here to explore using dynamic imports for lazying. Already today this can be done with late require-calls but you lose typing inference with that. Dynamic imports give you both, late and lazy loading and type safety/inference.

Sample times when not having cached data (very first startup, ~200 of 1500ms)

screen shot 2017-07-14 at 11 27 43

Sample times when having cached data (also node modules are cached, ~100 of 500ms)

screen shot 2017-07-14 at 11 29 04

Metadata

Metadata

Assignees

Labels

engineeringVS Code - Build / issue tracking / etc.perf

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions