Skip to content

Stop single icon lookups from building the constant-name index - #82

Merged
AdamMusa merged 12 commits into
mainfrom
fix/decouple-icon-sets
Nov 20, 2026
Merged

AdamMusa merged 12 commits into
mainfrom
fix/decouple-icon-sets

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

A single icon lookup used to build a whole icon set's constant-name index: one interned symbol per icon, 8,825 for Material. On the embedded mruby VM that is the ~300 ms cold-start cost the icon deferral exists to avoid. Two kinds of call did it:

  • MaterialIcons[name], CupertinoIcons[name], Icons.material[...] and Icons.cupertino[...].
  • Ruflet::Icons::<Cupertino-only name>. It built Material's index first, only to miss in it.

These lookups now answer from the compiled map and return the same result as before. Each icon set's file also loads without the other set's.

Every icon keeps the glyph it sends today. An earlier version of this PR sent Cupertino's codepoint for the 101 names both sets define (CupertinoIcons::ADD: 65604 became 131072). That change is backed out, together with the MaterialIconName/CupertinoIconName types and the new Icons.[] that it needed.

Changes

  • MaterialIcons.[] / CupertinoIcons.[]: some names, once upcased, are a compiled-map key that is also its own constant name. That holds for every key except CLASS_. For those names the map answers, in the map key's encoding, which is what the index returned (IconNames.own_constant_text). Other names go through the canonical lookup first, then the index, and otherwise come back as given. Only CLASS (for CLASS_) and names that are not icons still build the index.
  • Icons.const_missing: probes both compiled maps before either index, Material first as before. Icons::ICONS is the exception: its value is Material's index, so it still builds it, as on main. A different answer would need a name that is in Cupertino's map and in Material's index but not in Material's map. No such name exists: CLASS is the only name that needs an index, and neither map has it.
  • resolve_constant(name, index: true): passing index: false stops before the index is built, except for :ICONS, whose value is the index.
  • Set files: material_icons.rb and cupertino_icons.rb no longer require icon_data.rb, which loaded both sets' lookups. ruflet_ui.rb still requires icon_data first, so loading Ruflet is unchanged.

Behavior changes

None to any result. Every lookup returns the same text, class, encoding and frozenness as main and ruflet_core 0.0.23, and every control sends the same codepoint.

What a lookup builds and loads does change:

  • A single-name lookup no longer builds a constant index.
  • A set's file no longer loads the other set's lookup.
  • Ruflet::Icons::CLASS now probes the Cupertino map, which loads that set, before it builds Material's index. Main loaded only Material for it. The value is unchanged.

How the "no result changes" claim was checked: a script records 191,328 lookups.

  • Inputs: all 10,046 distinct names (8,825 Material and 1,322 Cupertino, 101 of them in both), in lower case, as Symbols and as constant names, plus other spellings: mixed case, spaces, dashes, icons. prefixes, numeric strings and unknown names.
  • Entry points: cold and warm Icons[]; MaterialIcons and CupertinoIcons [], constants, all and random; Icons.material and Icons.cupertino; IconData; plain strings and symbols.
  • Recorded output: each lookup rendered on button, cupertino_button and icon, plus page.update for the 101 shared names, and YAML and Marshal output.

This branch matches main dd924eb and 0.0.23 on all 191,328, and main matches 0.0.23. Object addresses in inspect output were normalized before comparing.

Tests

  • packages/ruflet_core/test/icon_set_decoupling_test.rb has 11 tests. 9 of them pin current behavior, so they also pass on main:

    • Published codepoints: CupertinoIcons::ADD 65604, ::HOME 69217, ::HOUSE_FILL 131732, Icons.cupertino[:add] 65604, MaterialIcons::CLASS 66925. Gems 0.0.15 to 0.0.21 and 0.0.23 send the same values; 0.0.22 is not installed here.
    • All 101 shared names through 8 entry points on 3 control families.
    • page.update.
    • CupertinoIcons.all and random.
    • Set names stay plain, mutable Strings in YAML and Marshal.
    • Icons[] as main has it: IconData before the constant is referenced and String after; Icons[:class] resolving after Icons::CLASS; "arrow back" raising NameError.
    • An equivalence check of every name and spelling against the index-first order (text, encoding, frozenness).
    • Material-only code never loads Cupertino.
    • The control families load separately.

    The other 2 fail on main: single lookups build the index, and a set's file loads the other set's lookup. I planted 8 mutations and the tests caught all 8: no encoding, no own-constant check, umbrella index-first, icon_data require re-added, no fast path, a changed Icons.[], controls resolving Cupertino first, frozen all.

  • H1 goldens: a new icons_app fixture has one control per way an app names an icon. Its page golden was generated on main and is unchanged here. On this PR's previous head merged with main, the same golden fails, because Icons[:class] raises ArgumentError.

  • On this head (d31bd0e), one process per test file: ruflet_core 1095 runs (one skip that main also has), ruflet_server 49, ruflet 513 (compat_goldens_test 243) and ruflet_rails 293 under bundle exec in an exported tree all pass. ruby test/compat/compat.rb --jobs 4 checks 235 goldens and exits 0. The whole ruflet_core suite also passes under Ruby 3.4.5.

  • Embedded VM: an arm64 macOS VM built from this branch's ruflet_core passes tools/embedded_vm_harness/tests/icon_deferral_test.rb (30 checks). That covers the codepoints above, Icons[:class] and the index staying unbuilt. A VM built from main fails only the 2 index checks. compat_test and regexp_test stop at their known lines (67 and 132), the same as on main, and scoped_helper_test and run_in_process_test.sh pass.

Not in this PR

  • Sending Cupertino's glyph for shared names that come from CupertinoIcons. It would change what apps show, so it needs the owner's decision.
  • On main and 0.0.23, the class of Icons[name] depends on whether the constant was referenced first: IconData before, String after. 0.0.15 to 0.0.21 always returned String. Left as is, because either fix changes the output in one of the two cases.
  • Code that uses only Cupertino icons still loads the Material table. Resolving Material first, which is what keeps the glyphs, needs it.
  • No prebuilt VMs are rebuilt or committed.

Merge gate (head 3e0e50d = approved d31bd0e + merges of main up to bc69c0b)

The merges bring in #88, #77, #86, #71, #76 and #107. All were clean, and this PR's diff against main is unchanged. One process per test file:

Material and Cupertino share 101 icon names (ADD, HOME, CHEVRON_LEFT, ...)
with different codepoints. Every icon prop resolved its value Material
first, and the constants were bare strings, so CupertinoIcons::ADD on any
control -- cupertino_button included -- sent Material's ADD (0x10044)
instead of 0x20000. The same path parsed the 234KB Material table for an
app that only ever used Cupertino icons.

Names now carry their set: MaterialIcons and CupertinoIcons hand out
MaterialIconName / CupertinoIconName, String subclasses that still compare,
hash and interpolate as the plain name. Control, Page and IconData resolve
icon props through IconData.codepoint_for, which looks a tagged name up in
its own table only. A plain string keeps the old order (Material, then
Cupertino), so existing apps render the same.

Also:
- material_icons.rb and cupertino_icons.rb no longer require icon_data,
  which pulled the other set's lookup in; each set file now loads alone.
- Icons.[] probed const_defined?, which is false for every deferred icon,
  so it returned IconData before a constant was first referenced and a
  String after, and raised NameError for "arrow back". It now probes the
  compiled maps.
- MaterialIcons[name] and Icons::<Cupertino-only name> built Material's
  8,825-symbol constant index for a single lookup -- the cost the deferral
  exists to avoid. Single-name lookups now answer from the compiled map.

Tests: test/icon_set_decoupling_test.rb (12 tests, 9 fail without the fix)
and new set-identity checks in the embedded-VM icon_deferral_test, which
passes on an arm64 VM built from this branch. The prebuilt VMs still carry
the old framework until they are rebuilt.
The previous commit sent Cupertino's codepoint for the 101 names both sets
define (CupertinoIcons::ADD went from 65604 to 131072). Every published
ruflet_core, 0.0.15 through 0.0.23, sends Material's codepoint for those
names whichever set they came from, so apps show that glyph today. That
change is backed out, and with it the MaterialIconName/CupertinoIconName
tags it needed: set names are plain, mutable Strings again, and
Control, Page, IconData and Ruflet::Icons[] are as on main. That also
undoes the Icons[:class] regression (after Icons::CLASS it resolves to
class_ again).

What stays changes no result, only what a lookup builds:
- MaterialIcons[name] and CupertinoIcons[name] try the compiled map
  before the constant-name index, so a single lookup no longer interns a
  symbol per icon. CLASS (for CLASS_) is the only name that needs the
  index, and it still gets it.
- Icons::NAME probes both compiled maps before either index, so a
  Cupertino-only name such as HOUSE_FILL no longer builds Material's.
- material_icons.rb and cupertino_icons.rb no longer require icon_data,
  so each set file loads without the other.

The tests now pin the published wire output: all 101 shared names through
every entry point and control family, CupertinoIcons.all/random,
page.update, the types and serialization of set names, and Ruflet::Icons[]
as main has it. An equivalence test checks every name and common spelling
against the index-first order. The embedded-VM harness checks the same
codepoints.
MaterialIcons[:home] read the compiled map first and returned the
caller's text downcased, so a Symbol argument came back US-ASCII where
the constant-name index had returned the map key's UTF-8 text (same
bytes, but Marshal output and #encoding differed). A map key that is its
own constant name is now answered with that key's encoding, as the index
did; everything else falls through to the old order.

The equivalence test now compares text, encoding and frozenness for every
name in both sets, binary-string and Symbol spellings included, and checks
that no two icons share a constant name, which the map-first answer relies
on.
None of the H1 goldens named an icon through MaterialIcons, CupertinoIcons,
Icons or IconData, so a change to the codepoint those send was invisible to
them. The new icons_app fixture has one control per way an app names an
icon, including names both sets define, a Cupertino-only name and CLASS.
Its page golden was generated with main (dd924eb) and is unchanged here.
0.0.15 to 0.0.21 and 0.0.23 were checked (all 101 shared names through
CupertinoIcons constants, [] and Icons.cupertino); 0.0.22 is not
installed here, so the comments no longer claim it.
@AdamMusa AdamMusa changed the title Keep each icon set's codepoint and stop loading the other set Stop single icon lookups from building the constant-name index Nov 20, 2026
@AdamMusa
AdamMusa merged commit 3cb9418 into main Nov 20, 2026
17 of 18 checks passed
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