Skip to content

perf: load icon sets only when the picker is used, cache single icons, fix tabler - #185

Merged
dnnsjsk merged 3 commits into
inline0:mainfrom
Contributolo:perf/icon-payload-slim
Oct 26, 2026
Merged

dnnsjsk merged 3 commits into
inline0:mainfrom
Contributolo:perf/icon-payload-slim

Conversation

@Contributolo

Copy link
Copy Markdown
Collaborator

Related to #8 (the ZIP size itself is not addressed here).

The icon field loaded and stored far more than it needs.

Frontend: bs_render_icon() stored the complete decoded set as a 30 day transient on the first render of any icon. Without a persistent object cache that is a row of up to 5 MB in wp_options (1,289,328 B for fontawesome-free solid, 5,055,377 B for simple-icons) next to the per-icon row. Only the rendered icon is cached now (369 B and 838 B written on a first render), and a set file is decoded at most once per request. Set transients written by earlier versions expire within 30 days and are then removed by the daily delete_expired_transients event, so there is no migration. Render output and the stored value {set, subSet?, icon} are unchanged.

Editor: every icon field fetched its whole set from /blockstudio/v1/icons as soon as the block was selected (1.3 MB for fontawesome-free solid, 5.1 MB for simple-icons, 2.8 MB for tabler outline), although the SVGs only render once the dropdown opens. The set is now requested on first focus of the picker or when the set or sub set changes. A closed field lists the stored icon, the combobox shows its spinner while the set loads, and a failed request no longer leaves the field without a picker. The REST response is unchanged. Selecting a block with two icon fields went from two requests (about 1.7 MB) to none; opening the picker fetches one set and lists the same 1,984 options with the same previews.

Tabler: the picker requested set=tabler-icons, but the files are tabler-icons-outline.json and tabler-icons-filled.json, so the request failed and tabler never showed up. The sub sets are now listed as in the files. The default sub set was always solid (the fontawesome-free check is always true), which remix-icons, material-design-icons and tabler do not have, so switching to those sets requested a missing file. The default now follows the set: a configured sub set the set has, then solid, then its first one.

Tests: PHPUnit for bs_render_icon() (no set transient, per-icon transient written and served, missing set and icon silent; two cases fail against the old code), client tests for the picker options and for the set map against the files in includes/icons (fail with the old tabler entry), and two cases in the icon E2E. Measured in WordPress Playground (WordPress 7.1, PHP 8.4); the E2E cases were not run locally (no Docker), the same flows were checked by hand in the editor there. npm run check passes.

bs_render_icon() wrote the complete decoded set (up to 5 MB for simple-icons) into a 30 day transient on the first render of any icon, which lands in wp_options without a persistent object cache. Only the rendered icon is cached now, and a set file is decoded at most once per request. Set transients left by earlier versions expire within 30 days and are removed by the daily delete_expired_transients event.
Every icon field mounted fetched its whole set from /blockstudio/v1/icons (up to 5 MB of SVG markup) and kept it in the store, although the SVGs are only rendered once the dropdown is open. The set is now requested on the first focus of the picker or when the set or sub set is changed. A closed field lists just the stored icon, the combobox shows its loading state while the set arrives, and a failed request no longer leaves the field without a picker. The REST response is unchanged.
The picker requested the set tabler-icons, but the files are tabler-icons-outline.json and tabler-icons-filled.json, so tabler never showed up. The sub sets are listed as in the files. Switching to a set whose sub sets do not include solid also kept solid as the sub set and requested a file that does not exist (remix-icons.json). The sub set now follows the set, preferring a configured one, then solid, then the first.
@Contributolo

Contributolo commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

E2E check with the Playground runner from #189, this branch merged onto main and built: tests/e2e/types/icon.ts and tests/e2e/types/repeater/minimized.ts, 31 passed (1.1m). Three runs, each on a fresh site: two 31/31; in the second run the first icon test (icon › defaults › add block) timed out (1 failed, 7 passed, the rest of the serial file did not run), and the third run with the same files passed again. This matches the occasional start-up failure described in #189.

@dnnsjsk
dnnsjsk merged commit 6def1a6 into inline0:main Oct 26, 2026
@dnnsjsk

dnnsjsk commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Released in Blockstudio 7.7.9. Thanks for the contribution.

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.

2 participants