You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Avoid constructor source scanning for classes without a base class in @loopback/context #11878
On the first call to describeInjectedArguments() for a constructor, LoopBack calls shouldSkipBaseConstructorInjection(), which reads the class’s source and runs regular expressions to determine whether constructor injections should be inherited.
This work also runs for classes that do not extend another class. For those classes, there is no base constructor to inspect. The metadata cache avoids repeated work for the same class, but applications inspecting many distinct classes still incur this cost during startup.
The proposed change in describeInjectedArguments() is:
if (method === '') {
if (
Object.getPrototypeOf(target) !== Function.prototype &&
shouldSkipBaseConstructorInjection(target)
) {
options.ownMetadataOnly = true;
}
}
Logs
Additional information
We measured the following application startup timings with @loopback/context 9.0.0, Node.js 22.23.4, and macOS 26.7 on an Apple M4 Pro:
Measurement
Original
With proposed guard
Constructor inspection
147.9 ms
18.5 ms
Overall component registration
224 ms
98 ms
These are medians of three fresh processes per variant, alternating between variants with other startup settings held constant. Of 3,948 inspected classes, 3,384 had no base class.
The improvement saves approximately 126 ms during registration. Constructor inspection is included in registration, so these savings are not additive or a claim about total application startup time.
Activity