Commit e98ce2f
authored
Optimize Service Container generation (#649)
## Context
Before this PR, each service would get its own lazy ivar within the
service container. If a service depended on another service then, it
would reference that dep's getter. This allowed it to lazily instantiate
all its deps as needed. However in some cases a service may not be used,
or may only be used once. In both cases, that service doesn't need to
have its own ivar.
This PR optimizes the service container to not generate ivars for those
kind of services. Services that are not used at all are just now not
included in the container at all. Services that are used once are simply
inlined into the getter of the service that needs it, however nested
they are.
For the `framework` component, this ultimately brings the service ivars
from 36, down to just 14. This'll be just a bit less code to compile,
and maybe make the GC's job a bit easier.
## Changelog
- Do not generate ivars for unused services
- Inline services where possible1 parent 6d8196a commit e98ce2f
16 files changed
Lines changed: 1040 additions & 45 deletions
File tree
- .changes/unreleased
- src/components
- dependency_injection
- spec/compiler_passes
- src
- compiler_passes
- framework/src/ext/console/compiler_passes
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
0 commit comments