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

300x performance improvement deepkit/injector, 20x faster and smaller deepkit/rpc, new packages deepkit/bench, deepkit/run #640

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

marcj
Copy link
Member

@marcj marcj commented Mar 27, 2025

This is a work in progress.

deepkit/injector was rewritten in its core. We have a lot of performance improvements:

  • 2-4x improvement for very small containers (with less than 5 providers)
  • 300x improvement (and more) for bigger containers with like 1000-2000 providers. the old version used a big switch-case, the new one direct references

In general getting the reference to the DI factory directly allows to get the most performance increase. Doing it like this

const resolveService = injector.resolver(Service);

const service  = resolveService(); // direct reference to JIT factory

makes resolving dependencies optimal. There is no faster way, even writing it manually is not faster. This is the most optimal way to retrieve a service instance. By assigning the factory function now directly into dependency resolution makes the whole container almost optimal in performance (meaning there is no way to make it any faster). Currently it hovers around 100mio ops/s, which is nearly identical to doing return instance ||= new Service();

deepkit/rpc protocol was fundamentally changed and got a size improvment of 20x. A single action calls without parameters is now only 3 bytes (vs ~80bytes before).

  • The binary decoding/encoding has been optimized and increased rpc action execution from 200k to 4mio actions/s (full roundtrip with reply). (it could be faster but new Promise is slow and has max 7mio ops/s)
  • No-response actions (fire and forget) have been introduced which increase performance to 43mio actions/s
  • Message header parsing has been improved in performance from ~5mio ops/s to ~80mio ops/s

deepkit/run internal package to execute typescript in an easy way

deepkit/bench new package for benchmarks. we add now scripts to packages/*/benchmarks directly in our repo, which can be executed like

cd packages/rpc;
node --import @deepkit/run benchmarks/message.ts;

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

Successfully merging this pull request may close these issues.

1 participant