No string search from an offset: a linear scanner must split or slice (found in #2344)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- c
调研方向
Start with index_of and string handling in the interpreter, then read lib/template.eigs render and the linked #2345 benchmarks. Define and test the start-position behavior, including byte offsets inside multibyte characters and both strict modes; compare timings at two sizes. Update docs/SPEC.md, docs/llms.txt, API output, and a changelog fragment, then verify the old-versus-new render cases and four delimiter benchmarks.
由索引模型根据 Issue 内容生成。
描述
What is missing. index_of of [haystack, needle] always searches from the start of the string. There is no way to ask for the first match at or after a position. A scanner that walks a string therefore has two choices: cut the rest of the string off at each step, which copies it each time and is quadratic over the string, or split the whole string on the delimiter and stitch the pieces back together.
Minimal repro
s is "a{{b{{c"
print of (index_of of [s, "{{"])
print of (index_of of [s, "{{", 2])
The first call prints 1. The second raises index_of: expected a fixed-shape list with at most 2 elements. There is no call that returns 4, the second match, without slicing s.
Where it was found. #2344 and its fix #2345, in lib/template.eigs render. The old render sliced, and was quadratic in the number of placeholders: 30 seconds at 200,001. The new one splits on {{ and }}. It is linear, but a template dense with delimiters that do not pair up now costs interpreted work for each of them, where the old code skipped them in native code. At 100,000 delimiters the four shapes measured take 161 to 299 ms, against 0.3 to 0.6 ms on main (the table under "What it costs" in #2345's description). A search that starts at an offset would let render scan natively and stay linear.
Indexes are bytes today: for "é{{b", index_of gives 2 and len gives 5.
Done when
- A string search can start at a position: either a third argument to
index_ofor a new builtin, decided in the pull request with the reason. It returns the index of the first match at or after the start, in the unitindex_ofreturns today, and-1when there is none. - A start that is negative, past the end, not an integer, or inside a multi-byte character has a stated behaviour, with a test for each. A haystack or needle that is not a string raises, in the default mode and with
EIGS_STRICT=0. - It does not copy the haystack: n searches over a string of n bytes with n matches run in time linear in n, shown by timings at two sizes.
-
docs/SPEC.md,docs/llms.txtandeigenscript --apishow it, and a changelog fragment is added. -
lib/template.eigsrenderuses it: the exhaustive old-against-new test of #2345 still passes, and the four shapes of #2345's "What it costs" are within noise ofmainat 100,000 delimiters. If the pull request grows large, split this box into its own issue and link it here.
Found while fixing #2344; out of that change's scope, so it is filed and not worked around.
— Claude DevBox
- 主要语言
- C
- 星标
- 3
- 派生
- 7
- 平均合并
- 6 小时 32 分钟
- 30 天内合并 PR
- 285
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
InauguralSystems/EigenScript 的其他 Issue
-
good first issue needs-triage
难度 1/5 1 小时以内 新手友好度 88/100
InauguralSystems/EigenScript#2347 · 1 条评论 ·
维护者通常 1 天内回复
-
needs-triage
难度 1/5 1 小时以内 新手友好度 82/100
InauguralSystems/EigenScript#2335 · 1 条评论 ·
维护者通常 1 天内回复
-
area:embed kind:bug
难度 2/5 1-3 小时 新手友好度 62/100
InauguralSystems/EigenScript#2311 · 1 条评论 ·
维护者通常 1 天内回复
-
area:gates kind:gate-defect
难度 2/5 1-3 小时 新手友好度 62/100
InauguralSystems/EigenScript#2305 · 1 条评论 ·
维护者通常 1 天内回复
-
area:ci bug found-by:duet-audit
难度 2/5 1-3 小时 新手友好度 62/100
InauguralSystems/EigenScript#2283 ·
维护者通常 1 天内回复
查看 InauguralSystems/EigenScript 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
FujiNetWIFI/fujinet-config#379 ·
维护者通常 1 天内回复
-
Ship /Local/Applications, the Local domain's Applications folder可能已有人在做 @pkgdemon 今天认领。 未关闭area:base enhancement
难度 1/5 1 小时以内 新手友好度 94/100
nextbsd/nextbsd-userland#612 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
zephyrproject-rtos/zephyr#125543 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
colbymchenry/codegraph#3277 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100