Avoid constructor source scanning for classes without a base class in @loopback/context
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 72/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- node.js, typescript
- 领域
- backend, performance
调研方向
首先阅读 @loopback/context 中的 describeInjectedArguments() 和 shouldSkipBaseConstructorInjection(),然后检查现有的构造函数注入和继承测试。确认没有基类的类会跳过源代码扫描,而有基类的类会保留现有行为;运行相关测试以验证这两种情况。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- TypeScript
- 星标
- 5.1k
- 派生
- 1.1k
- 平均合并
- 2 天 11 小时
- 30 天内合并 PR
- 50
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
loopbackio/loopback-next 的其他 Issue
-
Docs good first issue help wanted
难度 1/5 1-3 小时 新手友好度 68/100
loopbackio/loopback-next#683 · 3 条评论 ·
维护者通常 2 天内回复
-
难度 3/5 1-2 天 新手友好度 68/100
loopbackio/loopback-next#11869 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 55/100
loopbackio/loopback-next#11726 ·
维护者通常 2 天内回复
-
bug
难度 5/5 一周以上 新手友好度 35/100
loopbackio/loopback-next#11500 · 1 条评论 · 1 个 reaction ·
维护者通常 2 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 35/100
loopbackio/loopback-next#11412 · 1 条评论 ·
维护者通常 2 天内回复
查看 loopbackio/loopback-next 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
Northeastern-Electric-Racing/FinishLine#4660 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 86/100
excaliburjs/Excalibur#3895 ·
维护者通常 3 天内回复
-
infer_audio_type only recognises one MPEG Layer III frame header, so most MP3 files are rejected可能已有人在做 @Steve-20-ai 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Earn report crashes with "RangeError: Invalid time value" when a report row has an unparsable timestamp可能已有人在做 @Gurkaran18 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 75/100
joinmarket-webui/jam#1588 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
mihaip/infinite-mac#475 ·