Repository navigation
Commit 872bd57
committed
perf: build each distinct sprite image once
The game encoded 2,291 sprite PNGs as its modules loaded, and 845 of
them (37%) were an image already built: flash frames of sprites whose
flash palette matches, wear stages with no wear yet, and glyph tones
with the same colors. Each encode is a base64 PNG data URL on the main
thread behind the splash.
The data URL is now kept by the image's content, its size and every
run of pixels in paint order, so an identical image reuses the first
one's data URL. The 1,446 distinct images come out byte for byte the
same (one hash over every built source before and after), and sprite
building at load drops from about 107 ms to 87 ms in Bun, with the
encoder's own time from 56 ms to 40 ms.1 parent eae384c commit 872bd57
1 file changed
Lines changed: 32 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
149 | 165 | | |
150 | 166 | | |
151 | 167 | | |
152 | 168 | | |
153 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
154 | 173 | | |
155 | 174 | | |
156 | 175 | | |
157 | 176 | | |
158 | | - | |
159 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
160 | 189 | | |
161 | 190 | | |
162 | 191 | | |
| |||
0 commit comments