Skip to content

fix(seq,du,sed): buffered seq output, POSIX drive-form operands for du/sed, CHANGELOG #1167/#1169 - #1178

Merged
caomengxuan666 merged 3 commits into
mainfrom
fix/1173-1175-seq-posix-changelog
Oct 13, 2026
Merged

caomengxuan666 merged 3 commits into
mainfrom
fix/1173-1175-seq-posix-changelog

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1173, closes #1174, closes #1175.

Three independent tickets, one commit each.

#1173 — seq: batch stdout + integral to_chars fast path

Root cause. safePrint issues one WriteFile per call; seq emitted per line (separator + number), paying a kernel transition two-three times per line (~30us/line piped).

Fix (src/commands/seq.cpp):

  • Lines assemble into a 64 KiB buffer flushed in large chunks — byte stream identical, syscall count ~1 per buffer.
  • Integral fast path like GNU seq.c's integer bypass: integral FIRST/INCREMENT, default fixed format with precision 0, no --format, no -w, and all operands within the exact-integer double range (<= 2^52, which also keeps the range test on the next item exact) emit through std::to_chars. The endpoint-rescue can never fire on an integral sequence (an integral NEXT equal to LAST satisfies in_range), so the loop is a straight integer walk.
  • Floating path: one snprintf per line into a stack buffer instead of a size-query + write pair; the default format string is built once (overlong outputs fall back to the old heap path).

Benchmark (seq 1 100000, same box, warm runs):

scenario before after GNU (WSL oracle)
seq alone (> /dev/null), release ~332ms (issue), 758ms Debug ~44-49ms (release) 7-10ms
seq 1 100000 | wc -l ~900-1290ms ~39-50ms (release) 7-10ms
Debug build, seq alone 758ms 62ms —

Target met: 100k lines total <50ms in release. The residual vs GNU is the ~40ms Windows process-spawn floor (seq 1 1 costs ~40ms release), not per-line work (now ~0.05us/line).

New tests: seq_large_range_buffered_output_matches_gnu_bytes (588895 bytes / 100000 lines across several flush rounds, first/last bytes pinned) and a -s, , 50k-line variant asserting flush boundaries keep the byte stream. Differential-tested byte-identical against WSL GNU seq on 12 integral/decimal sequences incl. 10 -2 1, 1 2 9.5, 1 0.5 5.

Out-of-scope observation (pre-existing on main, untouched here): seq -w 1 2 10 pads to the max emitted value width instead of GNU's width-of-LAST (01 03 05 07 09 vs GNU 01 03 05 07 09 padded to 2 with last=10 wider than every emitted item).

#1174 — du/sed: POSIX /d/... operands resolve through the shared boundary

Root cause. The L2 self-parse contract was uneven: grep/wc/head/find route path operands through native_path, but du took operands straight into Win32 calls (ENOENT for /d/repo) and sed opened them verbatim.

Fix — both now use the same boundary helpers as grep/wc/head:

  • du (src/commands/du.cpp:1266-1289): traversal operands fold via make_api_path_operand_w (/d/src, /cygdrive/d/src, /dev pseudo-paths); -X exclude files and --files0-from sources normalize at open. Operand line and child entries agree on the resolved forward-slashed spelling (Savannah #13956); the [bug] du 对带尾斜杠参数输出双斜杠路径:du -h src/ 打印 src//bin(GNU 归一化) #1159 trailing-separator collapse is preserved against the raw operand and error messages keep the text as typed.
  • sed (src/commands/sed.cpp:2517-2567, 2577, 2609, 2626): input operands (glob patterns included) fold before expansion/open; with -i the folded path is what gets atomically replaced; -f script files and the r/w/W script-embedded paths resolve the same way. Diagnostics and the =/F filename display keep the operand text as typed.

Evidence. RED (main): du -sh /c/... rc=1 ENOENT while du -sh C:/... rc=0; sed -n 1p /c/.../in.txt rc=2. GREEN: both forms rc=0 with identical sizes; sed -i/sed -f work through POSIX paths. GNU oracle (WSL): du -sh /usr -> 8.5G /usr rc=0. New dual-form tests: du_accepts_posix_drive_form_operands (du -sh, sizes equal across forms), du_accepts_posix_drive_form_without_summarize, sed_accepts_posix_drive_form_operands (sed -n 1p), sed_in_place_accepts_posix_drive_form_operand, sed_script_file_accepts_posix_drive_form_operand.

#1175 — CHANGELOG [Unreleased] completion

Verification

  • Full unit suite: 2839 tests, 2839 passed, 0 failed (Debug, this branch); du 50/50, sed 120/120, seq 29/29.
  • Release build benchmark numbers above; GNU/WSL oracle timings recorded.
  • I18N review: no new user-visible message strings (comments, behavior, and tests only); existing catalog keys unaffected — no i18n repo sync needed.
  • clang-format applied to all touched files.
  • Note for reviewers: this branch was built with -DFETCHCONTENT_SOURCE_DIR_WINUXCMD_PCRE2 pointing at a local pcre2 10.47 checkout because the FetchContent download is blocked in my sandbox; CI downloads normally.

…th (issue #1173)

safePrint issues one WriteFile per call, so per-line emission paid a kernel
transition two-three times per line (~30us/line piped; 100k lines ~332ms
while GNU needs ~5ms). Lines now assemble into a 64 KiB buffer flushed in
large chunks, integral first/increment sequences (default fixed format,
precision 0, no --format/-w, |operands| <= 2^52) emit through std::to_chars
like GNU seq.c's integer bypass, and the floating path drops the per-line
size-query snprintf round trip.

100k lines, release build: seq 332ms -> ~45ms, seq | wc 903ms -> ~45ms
(GNU/WSL oracle: 7-10ms; residual is the ~40ms Windows process spawn).
Byte stream unchanged: new seq_large_range_buffered_output_matches_gnu_bytes
pins 588895 bytes/100000 lines across several flush rounds.
…ndary (issue #1174)

du rejected '/d/...' operands with ENOENT while accepting 'D:/...' and sed
could not read them either — the L2 self-parse contract (tools resolve POSIX
operands themselves) was unevenly applied. Both now route operands through
native_path::make_api_path_operand_w/normalize_api_operand, the same
boundary grep/wc/head/find already use:

- du: traversal operands (and -X exclude files, --files0-from sources) fold
  '/d/src', '/cygdrive/d/src' and /dev pseudo-paths to their Win32 form;
  operand line and child entries agree on the resolved forward-slashed
  spelling (Savannah #13956) while the #1159 trailing-separator collapse and
  error messages keep the operand text as typed.
- sed: input operands (glob patterns included) fold before expansion/open,
  and with -i the folded path is what gets replaced; -f script files and the
  r/w/W script-embedded paths resolve the same way. Diagnostics and the
  '='/F filename display keep the operand text as typed.

GNU oracle (WSL coreutils): du -sh /usr -> '8.5G /usr' rc=0. New tests cover
the dual forms: du -sh '/d/...' vs 'D:/...', sed -n 1p, sed -i and sed -f
through '/d/...' paths.
…wn resolver in [Unreleased] (issue #1175)

#1169 (GNU execvp-style child resolution: PATH-only bare-name search with no
cwd/System32 shadowing, POSIX PATH spellings normalized) and #1167 (touch
NTFS literal-glob platform deviation documented, test exemption registered)
were merged without a CHANGELOG entry. PR #1171's own fixes (#1170/#1168/
#1166) were already recorded at merge time (d4210c7), so no duplicate entry
is added for it.
@caomengxuan666
caomengxuan666 merged commit 9fb57a9 into main Oct 13, 2026
8 checks passed
caomengxuan666 added a commit that referenced this pull request Oct 13, 2026
…on (#1180)

- seq: 64 KiB chunked stdout + integral to_chars fast path, measured
  332ms -> ~45ms on 100k lines, byte stream unchanged (#1173).
- du, sed: POSIX drive-form operands resolve through the shared operand
  boundary like grep/wc/head/find (#1174).
- Retitle [Unreleased] to [1.1.7] (date slot left for the release
  commit). The #1176/#1177 wpm supply-chain entries were already
  recorded by #1179 itself.
@caomengxuan666
caomengxuan666 deleted the fix/1173-1175-seq-posix-changelog branch October 14, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant