Repository navigation
Commit b846710
perf(formula): the expression type checks build each typed check environment once per input, not once per call (#35000)
Fixes #34756
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
改了什么:表达式类型检查(`firstTypeMismatch`、`firstDateTextVerdict`、`firstDateTextCall`)以前每调用一次就重建一个带类型的
CEL 环境(克隆注册表、重新注册整套标准库)。现在按输入(作用域、日期类型、字段类型)缓存复用,最多 512 个,按最近最少使用淘汰。
- 为什么改:发布任何一个元数据时,运行时校验会把整个应用的每条表达式都检查一遍。实测在 showcase 上发布一个对象,要建 903
个环境(只有 97 种不同输入),光这一项就占约 0.5 秒。dogfood 的字段重排用例因此在繁忙的合并队列分片上超过 5 秒时限,把无关
PR 踢出了队列。
- 风险与回滚:检查只做解析和类型检查,共用环境与新建环境给出相同结论,报告内容不变;回滚即 revert。
-
先看:`packages/formula/src/cel-engine.ts`(缓存键与淘汰)、`packages/formula/src/cel-env-reuse.test.ts`。
- 两分钟验证:`pnpm --filter @objectstack/formula exec vitest run
src/cel-env-reuse.test.ts`,预期全部通过。
- 需要你做的:无,席位落地。
## What changes
The type checks behind the authoring rules built a new typed CEL
environment on every call. Each build clones cel-js's registry and
registers the whole stdlib again. The runtime authoring gate runs these
checks over every expression in the stack each time a metadata item is
published, so the cost grows with the size of the stack, not with the
size of the item.
- `packages/formula/src/cel-engine.ts`: the environments are kept per
input (scope, date typing and field types), up to 512, least recently
used first. The checks only parse and type-check against these
environments, so a shared one gives the same verdicts as a fresh one.
## Tests
- `packages/formula/src/cel-env-reuse.test.ts` (an existing harness; a
new `#34756` describe): repeated checks of one field map build no new
environment; the field types are part of the key, so the same source
keeps each map's own verdict; the scope and temporal typing are part of
the key too. The 512-entry cap and its eviction order have no pin of
their own: noted for the L1 review.
## Acceptance notes
- Opened by the seat on the maintainer's order (「#34638、#34756 由席位代开
PR」): the cloud dev session `session_012MmDsP9M4FjNJxrUMf7ESW` pushed
this branch, and its own permission classifier refused its relay
`pr_create`. This body is the seat's, written from the pushed commit and
changeset.
- Root cause, as the dev measured it: no timer or polling wait. The two
cases paid the publish path's per-expression environment rebuilds (about
0.5 s per publish on an idle machine; more under queue load). No
per-case timeout was raised or added, per the card's fence.
- `packages/formula/src/cel-engine.ts` is also edited by PR #34935
(#34662). The seat runs the overlap check before landing either.
## Verification
Measured by the dev on the showcase (from the changeset): one object
publish built 903 environments for 97 distinct inputs; the publish
request went from about 1.6–1.8 s to about 1.0–1.3 s on an idle machine.
CI on this PR, and a dogfood run of
`object-designer-field-reorder.dogfood.test.ts` under load, are the
seat's to read before landing.
---
_Generated by [Claude
Code](https://claude.ai/code/session_012MmDsS4GoHCgYwA2uv3n3C)_
<!-- signed: repo:objectstack#4 · os-lizheng ·
session_012MmDsS4GoHCgYwA2uv3n3C -->
Co-authored-by: Claude <noreply@anthropic.com>1 parent bcfc8e4 commit b846710
3 files changed
Lines changed: 123 additions & 1 deletion
File tree
- .changeset
- packages/formula/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1088 | 1088 | | |
1089 | 1089 | | |
1090 | 1090 | | |
1091 | | - | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
1092 | 1094 | | |
1093 | 1095 | | |
1094 | 1096 | | |
| |||
1102 | 1104 | | |
1103 | 1105 | | |
1104 | 1106 | | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
1105 | 1155 | | |
1106 | 1156 | | |
1107 | 1157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
0 commit comments