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
Open
perf: replace per-block SMIL animate with shared CSS keyframes in rainbow theme#148K-H-A-L-I-D wants to merge 1 commit intoyoshi389111:mainfrom
K-H-A-L-I-D wants to merge 1 commit intoyoshi389111:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
profile-night-rainbow.svgweighs ~375KB, more than double any other theme. The culprit isaddRainbowColor()increate-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 inlineanimation-delaythat encodes the week-based hue phase offset. That preserves the per-column rainbow wave. The 15@keyframesdefinitions (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:
Result
<animate>tags@keyframes+ 15 class rulesChanges
addRainbowColor()insrc/create-3d-contrib.tsnow sets a CSS class andanimation-delayinstead of appending<animate>. A new exported functiongetRainbowKeyframes()generates the 15 keyframe definitions and lives in the same file.src/create-svg.tsinjects that output into the SVG<style>block whensettings.type === 'rainbow'.