Avoid constructor source scanning for classes without a base class in @loopback/context
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- backend, performance
Research direction
Start by reading describeInjectedArguments() and shouldSkipBaseConstructorInjection() in @loopback/context, then check the existing tests for constructor injection and inheritance. Confirm that classes without a base class avoid the source scan while classes with a base class retain the existing behavior; run the relevant tests to verify both cases.
Written by the indexing model from the issue text.
Description
Describe the bug
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.
Reproduction
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 50
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from loopbackio/loopback-next
-
Docs good first issue help wanted
Difficulty 1/5 1-3 hours Newbie friendliness 68/100
loopbackio/loopback-next#683 · 3 comments ·
Maintainers usually reply within 2 days
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
loopbackio/loopback-next#11869 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
loopbackio/loopback-next#11726 ·
Maintainers usually reply within 2 days
-
bug
Difficulty 5/5 Over a week Newbie friendliness 35/100
loopbackio/loopback-next#11500 · 1 comment · 1 reaction ·
Maintainers usually reply within 2 days
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 35/100
loopbackio/loopback-next#11412 · 1 comment ·
Maintainers usually reply within 2 days
All issues in loopbackio/loopback-next
Similar issues
-
Add: Disco Mix SDOpencheck:passed streams:add
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
level2 nsoc26
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
GauravKarakoti/SecureFlow#1488 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
deltachat/deltachat-desktop#6914 ·
Maintainers usually reply within 2 days
-
area:cli bug P4
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
bug from-studio
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
esengine/DeepSeek-Reasonix#14868 ·
Maintainers usually reply within 1 day