Skip to content

fix(tokenizer): let the SSE2 loops in ToLower run - #21436

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
ccclucky:fix/tolower-sse2-blocks
Oct 28, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
ccclucky:fix/tolower-sse2-blocks

Conversation

@ccclucky

Copy link
Copy Markdown
Contributor

What

ToLower(const char*, size_t, char*, size_t) and ToLowerString both gate their 16-byte block loop on

const char* sse2_end = begin + (len & ~(SSE2_BYTES - 1));
char* p = begin;
for (; p > sse2_end; p += SSE2_BYTES)

p starts at begin and sse2_end >= begin, so p > sse2_end is false on entry and the vector body never runs. Every call is served by the scalar byte loop. Changing the comparison to < lets the blocks through and leaves the scalar loop to finish the tail.

Raised by @Harsh23Kashyap while reviewing #21433 as a pre-existing issue in the same file.

Scope

Two characters, no behaviour change. The mask is built from signed compares bytes > 'A'-1 and 'Z'+1 > bytes, which is already false for bytes >= 0x80, so non-ASCII bytes stay untouched exactly as the scalar path leaves them. ToLower(char*, size_t) was already correct (while (len >= 16)) and is not touched.

Verification

No repo test can observe this: the scalar path produces identical output, so only the executed path changes. Validated with a scratch harness against the header (not committed):

  • Vector body actually runs now. Instrumented copies of the old and new header count loop iterations for a 64-byte ASCII buffer: old 0 / 0, new 4 / 4 (once per 16-byte block in both functions).
  • Output equivalence. 256-byte buffer holding every byte 0x00-0xFF, lengths 0-96 built from ASCII/UTF-8 seeds, and 2000 random byte buffers, run through ToLowerString, the out-buffer overload (including the NUL terminator and no writes past len + 1) and the in-place overload. Vector build and scalar build emit the same FNV-1a digest, zero mismatches against a scalar reference.
  • Real intrinsics compile. clang++ -arch x86_64 -msse2 -std=c++20 -c on the header. The vector checks above were executed through simde aliases because this host is arm64; on aarch64 __SSE2__ is not defined and the block is compiled out either way.

Test plan

  • CI ragflow_native_backend builds the binding on x86_64
  • bash build.sh --test ./internal/tokenizer/... still passes

Both the out-buffer ToLower overload and ToLowerString compared the cursor
against the vector end with `p > sse2_end`. The cursor starts at `begin`
and `sse2_end` is never below it, so the condition was false on entry and
the vector body never executed: every call fell through to the scalar
byte loop. Compare with `<` so the 16-byte blocks are processed and the
scalar loop keeps handling only the tail.

Behaviour is unchanged; the mask built from signed compares is already
false for bytes >= 0x80, so non-ASCII bytes stay untouched.
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2903a625-3e5b-4abb-83b2-49dbbd7048f0
Commits

Reviewing files that changed from the base of the PR and between e5a5060 and ada6191.

Files selected for processing: 1
  • internal/binding/cpp/string_utils.h

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

Both ToLower overloads now process full 16-byte SSE2 blocks before the aligned end. Remaining bytes continue through the existing scalar conversion.

Changes: SSE2 lowercase processing

Layer / File(s) Summary
Correct SSE2 loop bounds
internal/binding/cpp/string_utils.h
Both ToLower overloads now process full SSE2 blocks before the aligned end. Remaining bytes use the existing scalar conversion.

Priority: Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related PRs

  • infiniflow/ragflow#21433: Adds ToLowerUTF8 and changes RAGAnalyzer to use it instead of ToLower; both PRs change lowercasing behavior in tokenizer analysis.

Suggested labels: 🐞 bug, parsing

Merge Risk: Minimal · up to ada61

No merge-blocking issue was identified in the loop-bound correction.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the fix and its location: the SSE2 loops in ToLower now run. It matches the main change, which switches the 16-byte loop condition from p > sse2_end to p < sse2_end. It uses the conven…
Description check Passed The description follows the repository template. It has a clear What section that explains the bug (the p > sse2_end guard prevents the vector body from running) and the fix. It adds Scope, Verificati…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix and its location: the SSE2 loops in ToLower now run. It matches the main change, which switches the 16-byte loop condition from p > sse2_end to p < sse2_end. It uses the conventional type(scope) prefix and is a single sentence of 8 words.

Full details: Description check

Explanation

The description follows the repository template. It has a clear What section that explains the bug (the p > sse2_end guard prevents the vector body from running) and the fix. It adds Scope, Verification, and Test plan sections. The template's Summary section is not used under that exact heading, but the What section covers the same purpose and background, so the required information is present.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks each block with care
Sixteen bytes now pass through there
The trailing bytes take the scalar trail
Lowercase letters leave no detail
The SSE2 loops hop along
And finish with a tidy song

Comment @coderabbitai help to get the list of available commands.

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator

Verified the fix on source. With p < sse2_end the vector loop covers the whole 16-byte-aligned prefix and the last block load ends at sse2_end - 1, so no over-read; the scalar loop picks up the tail from there. The signed cmpgt mask keeps bytes >= 0x80 untouched (they compare negative against 'A'-1), which is exactly what the Cyrillic path in #21433 relies on, and the vector path agrees with the scalar one on the ASCII-only mapping. Good call spinning this out separately.

Source-level review only, no C++ toolchain in this environment.

@yuzhichang yuzhichang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking findings.

@yuzhichang yuzhichang added the ci Continue Integration label Oct 27, 2026
@ccclucky

Copy link
Copy Markdown
Contributor Author

Thanks for the source-level verification — the mask reasoning matches what we measured locally.

One note on the CI so nobody re-reads it as a code defect: ragflow_tests_infinity shows failure on head ada619168, but the job log says otherwise. Every step is success, including "Run Go API tests against Infinity" (ok ragflow/test/api 87.108s), and the sibling ragflow_tests_elasticsearch, ragflow_go_integration, ragflow_preflight and ragflow_python_sdk_unit are all green on the same commit. The only non-success entry is the post-test Complete job step, which reports no conclusion — same infrastructure step that also emits the Node.js 20 deprecation warning at the end of the job. So the red mark is the runner's teardown, not the change; the CI-workflow itself is out of scope here.

No code update needed for this thread.

@ccclucky

Copy link
Copy Markdown
Contributor Author

One operational note to go with the above: since ragflow_tests_infinity is reported as failure on head ada619168, it will keep the checks panel amber even though the PR is approved. A re-run of that job (or of the whole workflow run 40438236459) should turn it green with no code change — the test step itself already returned ok ragflow/test/api 87.108s. I don't have permission to trigger re-runs on a fork PR, so @yuzhichang could you re-run it when convenient?

@ccclucky

Copy link
Copy Markdown
Contributor Author

Correction to my earlier note on the ragflow_tests_infinity amber — I pulled the raw job log for run 40438236459 (job 121972231018) and the picture is narrower than "environmental flake":

  • The tests passed. Step 10 "Run Go API tests against Infinity" ends with ok ragflow/test/api 87.108s; the containers all came up healthy.
  • Every step in the job reports success (1–13 plus the post steps). The job-level conclusion is failure with no step-attributable error anywhere in the log — there is not a single ##[error] annotation.
  • The only Error: line is from Codecov: Found 0 coverage files to report / No coverage reports found. That step still finished green because it runs with fail_ci_if_error: false, so it cannot be the failing step either — but it does mean this job never produces coverage files for the Go path.

So the checks panel is amber on an approved, test-green PR because of the job wrapper, not because of anything in internal/rag/res or this diff. @yuzhichang @wangq8 — could you either re-run the job, or use the admin override to merge? If a re-run goes amber again the same way, that points at a sep-tests workflow issue worth its own look (happy to file it, but I won't touch CI files without your call).

For completeness, the other five checks on this head are green: ragflow_preflight, ragflow_go_integration, ragflow_tests_elasticsearch, ragflow_python_sdk_unit all success, ragflow_native_backend skipped by design.

@ccclucky

Copy link
Copy Markdown
Contributor Author

FYI: the red ragflow_tests_infinity job is not a test failure. Every step in that job reports success (build, unit tests, stack startup, Go API tests, teardown); the job itself is marked failed with this annotation:

The self-hosted runner lost communication with the server.

So the runner dropped out after the work finished. ragflow_preflight, ragflow_python_sdk_unit, ragflow_tests_elasticsearch and ragflow_go_integration all passed on the same commit. A re-run would clear it, but I cannot trigger one from a fork.

@xugangqiang xugangqiang added ci Continue Integration and removed ci Continue Integration labels Oct 28, 2026
@yuzhichang

Copy link
Copy Markdown
Member

No re-run needed — the checks are already green on this head.

ragflow_tests_infinity (and the other five) now report success on ada619168 from the newer run (40650924648), so the runner-teardown failure you saw in run 40438236459 no longer affects the checks panel. Nothing here points at the diff, and the approval stands.

Thanks for digging into the job log rather than calling it a flake — the "self-hosted runner lost communication" annotation is the operational issue, not this change. If it recurs on another PR, a separate CI issue is the right place for it.

@yuzhichang
yuzhichang merged commit f9ff41e into infiniflow:main Oct 28, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants