Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Avoid constructor source scanning for classes without a base class in @loopback/context

未关闭 适合新手
#11,878 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃

调研方向

首先阅读 @loopback/context 中的 describeInjectedArguments() 和 shouldSkipBaseConstructorInjection(),然后检查现有的构造函数注入和继承测试。确认没有基类的类会跳过源代码扫描,而有基类的类会保留现有行为;运行相关测试以验证这两种情况。

由索引模型根据 Issue 内容生成。

描述

bug
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

https://github.com/tonynelson19/loopback-constructor-repro

主要语言
TypeScript
星标
5.1k
派生
1.1k
平均合并
2 天 11 小时
30 天内合并 PR
50

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

loopbackio/loopback-next 的其他 Issue

查看 loopbackio/loopback-next 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。