Skip to content

perf(deparser): skip over-long SHOW segments before UTF-8 encoding - #394

Merged
pyramation merged 2 commits into
mainfrom
fix/deparser-show-split-bound
Nov 21, 2026
Merged

pyramation merged 2 commits into
mainfrom
fix/deparser-show-split-bound

Conversation

@pyramation

@pyramation pyramation commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

#393's DP split ran TextEncoder.encode() on every candidate segment, at every dot. For "a.".repeat(100000) + ".z", that allocates gigabytes. A segment with a JS length over 63 can never fit, because UTF-8 bytes ≥ UTF-16 length, so it's now skipped before encoding. Shorter segments still get the byte check. The PR adds a pathological-input test. Raised by CodeRabbit on #393.


libpg-query and parser opened this PR for Dan
Implemented in session Triage stale open PRs and issues in parser repos
Review with Devin · Open in Devin Desktop


Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of dotted SHOW names with many segments. Each segment is now limited to 63 characters and 63 UTF-8 bytes.
  • Tests
    • Added coverage to verify that deparsing handles names with many dot boundaries without attempting to encode oversized segments.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@luxor-code-review

luxor-code-review Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR bounds the encoding work done when deparsing a VariableShowStmt whose name contains many dot boundaries: character-length guards are now applied before entering the per-segment UTF-8 encoding loop, so an overlong identifier fails fast instead of doing quadratic encoding work. A new test in the deparser's pretty-print suite pins this behavior by asserting the bounded path completes and the unbounded path still throws.

Files Change
packages/deparser/src/deparser.ts Adds early character-length guards in the SHOW-name splitting path so encode calls are only made when a segment can plausibly fit the 63-byte identifier limit.
packages/deparser/__tests__/pretty/show-quoting.test.ts Adds a regression test asserting bounded encode work for a name with many dot boundaries and that an unbounded SHOW name still throws.

Note: two verified candidate findings (an inconsistent overlong-name fast path in deparser.ts and a time-based test assertion) fell just below the confidence threshold and are not included as formal findings.

Reviewed commit: ec41fac

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The deparser now limits SHOW name segments by both character count and UTF-8 byte length. A regression test covers deparsing a SHOW name with many dot boundaries.

Changes: SHOW name splitting

Layer / File(s) Summary
Enforce segment limits
packages/deparser/src/deparser.ts, packages/deparser/__tests__/pretty/show-quoting.test.ts
The split logic checks character count and UTF-8 byte length for candidate segments. A regression test checks deparsing a name with 100,000 repeated a. segments followed by .z.

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

Change: Refactor

Possibly related PRs

Suggested reviewers: luxor-code-review

Merge Risk: Minimal · up to ec41f

This change avoids large allocations when deparsing SHOW names with many dots, and accepted names keep the same behavior. No concrete merge-blocking risk was found.

Security architecture risk: Minimal · up to ec41f

The change avoids encoding identifier candidates that cannot satisfy the existing byte limit. No introduced or worsened architecture-level security risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the deparser now skips SHOW segments longer than 63 characters before UTF-8 encoding, which is a performance fix. The raw summary describes the same change in deparser…
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 main change: the deparser now skips SHOW segments longer than 63 characters before UTF-8 encoding, which is a performance fix. The raw summary describes the same change in deparser.ts (a 63-character check applied before the existing 63-byte check) and a pathological-input test. The objectives describe the same allocation fix. The title is specific and matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 2
  • Waived: $0.50 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 32bd943 and ec41fac.

Files selected for processing: 2

  • packages/deparser/__tests__/pretty/show-quoting.test.ts
  • packages/deparser/src/deparser.ts

Limit details: You’ve used all 10 included reviews currently available.

@devin-ai-integration devin-ai-integration 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@pyramation
pyramation merged commit b361b7d into main Nov 21, 2026
24 checks passed
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