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

comm: per-line get_flag lookups and allocation in the main loop

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
cli, performance

调研方向

从 src/uu/comm/src/comm.rs 开始,重点查看第 227、242 和 258 行附近的主循环,以及第 134、139 和 153 行附近的 OrderChecker::verify_order。分别在带有和不带 --nocheck-order 的情况下运行提供的 seq 和 comm 基准测试,然后运行现有测试。当查找次数和每行分配都减少,同时输出保持逐字节一致且性能得到提升时,即可视为完成。

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

描述

U - comm

In comm, the main loop calls opts.get_flag(options::COLUMN_1/2/3) on every line (lines 227, 242 and 258 of src/uu/comm/src/comm.rs) which is a clap lookup by string.
OrderChecker::verify_order also does self.last_line = current_line.to_vec() on every line (lines 134, 139 and 153), so each line allocates.

Setup: Debian 13, aarch64 (Docker VM), LC_ALL=C, release build of main at 070d78da1 (LTO off), GNU coreutils 9.7.

How to reproduce:

seq -f 'k%08.0f' 1 2 2000000 > ca
seq -f 'k%08.0f' 1 3 3000000 > cb
LC_ALL=C comm -123 ca cb

Time, median of 9 runs:

GNU 9.7 main patched
comm ca cb > file 101 ms 197 ms 117 ms
comm -123 ca cb 67 ms 159 ms 85 ms
comm --nocheck-order -123 ca cb 60 ms 99 ms 67 ms

With --nocheck-order the order checker never runs so only the flag lookups differ. The number of write calls is identical before & after, so the output side is not the cause.

My patch hoists the three flags out of the loop and reuses the buffer (clear() + extend_from_slice). It's 25 lines, byte-identical to GNU's output and the existing tests pass.

For transparency, I noticed this issue thanks to an LLM.

主要语言
Rust
星标
24.3k
派生
2.1k
平均合并
1 天 16 小时
30 天内合并 PR
310

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

uutils/coreutils 的其他 Issue

查看 uutils/coreutils 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

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