Skip to content

perf: replace per-block SMIL animate with shared CSS keyframes in rainbow theme#148

Open
K-H-A-L-I-D wants to merge 1 commit intoyoshi389111:mainfrom
K-H-A-L-I-D:perf/css-keyframes-rainbow
Open

perf: replace per-block SMIL animate with shared CSS keyframes in rainbow theme#148
K-H-A-L-I-D wants to merge 1 commit intoyoshi389111:mainfrom
K-H-A-L-I-D:perf/css-keyframes-rainbow

Conversation

@K-H-A-L-I-D
Copy link
Copy Markdown

@K-H-A-L-I-D K-H-A-L-I-D commented Apr 14, 2026

Problem

profile-night-rainbow.svg weighs ~375KB, more than double any other theme. The culprit is addRainbowColor() in create-3d-contrib.ts. It appends an inline SMIL <animate> element to every rect face, and with ~364 blocks at 3 faces each, that produces ~1,092 animate elements. Each one repeats 7 full RGB color-stop strings. About 240KB of the file is nothing but duplicated animation markup, which makes the SVG slow to parse and noticeably sluggish when embedded in a profile README.

Solution

Every rect gets a CSS class (rb-l{level}-{top|left|right}) and an inline animation-delay that encodes the week-based hue phase offset. That preserves the per-column rainbow wave. The 15 @keyframes definitions (5 contribution levels times 3 faces) live once in the SVG <style> block instead of being duplicated across every element.

The delay that maps each block to the right starting phase:

delaySeconds = -((week * hueRatio % 360 + 360) % 360 / 360) * durationSeconds

Result

Before After
Animation elements ~1,092 <animate> tags 15 @keyframes + 15 class rules
Animation overhead ~240KB ~5KB
Total SVG size ~375KB ~140–150KB
Visual output Per-block rainbow cycle Identical

Changes

addRainbowColor() in src/create-3d-contrib.ts now sets a CSS class and animation-delay instead of appending <animate>. A new exported function getRainbowKeyframes() generates the 15 keyframe definitions and lives in the same file. src/create-svg.ts injects that output into the SVG <style> block when settings.type === 'rainbow'.

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