Skip to content

perf(layout): bound cleanup memory for large region groups - #522

Open
CyMule wants to merge 3 commits into
mainfrom
perf/bound-layout-cleanup-memory
Open

CyMule wants to merge 3 commits into
mainfrom
perf/bound-layout-cleanup-memory

Conversation

@CyMule

@CyMule CyMule commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Large connected groups of detected regions still allocated several full N×N floating-point arrays during cleanup, even after grouping. Compare only the current candidate row, preserving the existing containment decisions, output ordering and every element attribute. Working comparison memory is now linear in the group size; worst-case comparison time can remain quadratic.

Tested on the dedicated SND nick-oom-perf-oct01 using uticplatform.azurecr.io/core-product-api:20260928-173342, two CPU cores and equal memory limits, against current main. A 4,000-region connected-chain workload through PageLayout and the detection-model deduplication path used median peak RSS 1,098.86 → 350.32 MiB and 0.641 → 0.273 seconds across three alternating runs, with identical complete output hashes. Under a 768 MiB limit the baseline pod was OOMKilled (137); this branch completed with the same output. The detector is synthetic so these figures measure the layout-processing stages, not end-to-end document inference latency.

Validation:

  • Full non-slow unit suite, Ruff and formatting pass locally; CI (tests on 3.11–3.13, lint, changelog/version) is green.
  • Regression coverage includes exact dense-reference parity, all element attributes, degenerate/nonfinite/extreme coordinates, containment thresholds, allocation bounds and detection-pipeline routing.
  • Independent review compared the actual main function across 6,000 cases, including six input dtypes and ten thresholds, with identical outputs and output dtypes.
  • The built wheel passed the SND regression suite and a real three-page YOLOX + OCR PDF partition: nine identical elements and three calls through the changed cleanup function on both sides.

This is independent of #521, which removes the grouping matrix at the preceding stage. Versions are staggered across the open inference PRs: #518 → 1.6.14, #520 → 1.6.15, #521 → 1.6.16, this PR → 1.6.17; merge them in that order (each rebases its changelog entry above the previous one). Downstream pins still need to adopt the release. These reproductions establish a concrete OOM fix, not attribution or elimination of all production OOMs.

Review in cubic

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T22:43:54.621367Z 96ee2a9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 5 files

Shadow auto-approve: would not auto-approve. This PR does not meet the repository auto-approval settings.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 issues found across 4 files (changes from recent commits).

Shadow auto-approve: would not auto-approve. This PR does not meet the repository auto-approval settings.

Re-trigger cubic

@CyMule
CyMule marked this pull request as draft October 2, 2026 03:33
@CyMule
CyMule marked this pull request as ready for review October 2, 2026 04:13
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 5 files

Shadow auto-approve: would not auto-approve. This PR does not meet the repository auto-approval settings.

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant