Skip to content

perf(shorthandCss): merge each distinct style value only once - #1899

Open
cossssmin wants to merge 1 commit into
masterfrom
perf/shorthand-css-cache
Open

cossssmin wants to merge 1 commit into
masterfrom
perf/shorthand-css-cache

Conversation

@cossssmin

@cossssmin cossssmin commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

shorthandCss ran a full postcss + postcss-merge-longhand pass for every single style attribute. Utility-generated emails repeat the same inline styles a lot, so most of those runs were redoing the same work.

It now caches the merged result per distinct style value, for the duration of one call (no module-level state, so nothing builds up in long-running processes).

Numbers

shorthandCss alone:

Email style attributes (distinct) Before After
Typical order email (12KB) 107 (33) 3.6ms 1.3ms
Long email (48KB) 627 (33) 18.3ms 1.2ms

Full warm render with the renderer reused: ~41ms → ~36ms for the typical email, ~94ms → ~76ms for the long one.

Output is byte-identical on both emails, and there's a new test for repeated identical style values across elements and MSO conditional comments.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • CSS processing now consistently combines identical padding values into shorthand styles in paragraphs and table cells, including table cells within MSO conditional comments. This helps produce more compact, consistent inline styles across supported content.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: cca64a02-5ef1-4c1c-9c9e-eda76627da74

📥 Commits

Reviewing files that changed from the base of the PR and between 3a1003a and 6ae0b89.

📒 Files selected for processing (2)
  • src/tests/transformers/shorthandCss.test.ts
  • src/transformers/shorthandCss.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The transformer now caches merged inline-style results for each call and returns cached values for repeated styles. A test checks padding shorthand output on a paragraph, a table cell, and a table cell inside an MSO conditional comment.

Changes

CSS shorthand merging

Layer / File(s) Summary
Cache merged inline styles and verify output
src/transformers/shorthandCss.ts, src/tests/transformers/shorthandCss.test.ts
shorthandCssDom caches results by original style value during each call. It preserves and caches the original value when parsing fails or yields no declaration text. The test checks that the three elements produce padding: 4px 8px without a remaining padding-top declaration.

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

Merge Risk: ⚪ Minimal · up to 6ae0b

The supplied context identifies no material merge risk from this per-call optimization; proceed with normal checks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main performance change: caching shorthand CSS merges so each distinct style value is processed only once.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

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

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