Repository navigation
Stop single icon lookups from building the constant-name index - #82
Merged
Merged
Conversation
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.
This was referenced Nov 16, 2026
AdamMusa
marked this pull request as ready for review
November 16, 2026 06:24
This was referenced Nov 16, 2026
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.
4 tasks
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.
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[...]andIcons.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 theMaterialIconName/CupertinoIconNametypes and the newIcons.[]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 exceptCLASS_. 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. OnlyCLASS(forCLASS_) 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::ICONSis 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:CLASSis the only name that needs an index, and neither map has it.resolve_constant(name, index: true): passingindex: falsestops before the index is built, except for:ICONS, whose value is the index.material_icons.rbandcupertino_icons.rbno longer requireicon_data.rb, which loaded both sets' lookups.ruflet_ui.rbstill requiresicon_datafirst, 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:
Ruflet::Icons::CLASSnow 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.
icons.prefixes, numeric strings and unknown names.Icons[];MaterialIconsandCupertinoIcons[], constants,allandrandom;Icons.materialandIcons.cupertino;IconData; plain strings and symbols.button,cupertino_buttonandicon, pluspage.updatefor 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
inspectoutput were normalized before comparing.Tests
packages/ruflet_core/test/icon_set_decoupling_test.rbhas 11 tests. 9 of them pin current behavior, so they also pass on main:CupertinoIcons::ADD65604,::HOME69217,::HOUSE_FILL131732,Icons.cupertino[:add]65604,MaterialIcons::CLASS66925. Gems 0.0.15 to 0.0.21 and 0.0.23 send the same values; 0.0.22 is not installed here.page.update.CupertinoIcons.allandrandom.Icons[]as main has it:IconDatabefore the constant is referenced andStringafter;Icons[:class]resolving afterIcons::CLASS;"arrow back"raisingNameError.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_datarequire re-added, no fast path, a changedIcons.[], controls resolving Cupertino first, frozenall.H1 goldens: a new
icons_appfixture 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, becauseIcons[:class]raisesArgumentError.On this head (d31bd0e), one process per test file:
ruflet_core1095 runs (one skip that main also has),ruflet_server49,ruflet513 (compat_goldens_test243) andruflet_rails293 underbundle execin an exported tree all pass.ruby test/compat/compat.rb --jobs 4checks 235 goldens and exits 0. The wholeruflet_coresuite also passes under Ruby 3.4.5.Embedded VM: an arm64 macOS VM built from this branch's
ruflet_corepassestools/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_testandregexp_teststop at their known lines (67 and 132), the same as on main, andscoped_helper_testandrun_in_process_test.shpass.Not in this PR
CupertinoIcons. It would change what apps show, so it needs the owner's decision.Icons[name]depends on whether the constant was referenced first:IconDatabefore,Stringafter. 0.0.15 to 0.0.21 always returnedString. Left as is, because either fix changes the output in one of the two cases.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:
packages/ruflet_record. On 3e0e50d:ruflet_record6 files, 34 runs, 0 failures. Every other package is the same as on 5ad0d47.ruflet21 files, 647 runs;ruflet_railsunderbundle execin an exported tree, 17 files, 295 runs; 0 failures.ruby test/compat/compat.rb --jobs 4checked 291 goldens and exited 0.compat_goldens_test.rb: 299 runs, 0 failures.packages/ruflet. Soruflet_core,ruflet_server,ruby_runtimeandtoolsare the same as on ddc5257, the previous merge. Results on ddc5257:ruflet_core: 203 files, 2058 runs, 0 failures, 1 skip, on Ruby 4.0.5 and on 3.4.5. The skip isdsl_presented_controls_test, which needsRUFLET_ENGINE_ROOT; this PR does not touch it.ruflet_server: 51 runs, 0 failures.icon_deferral_test(30 checks), fix: read client-synced control state like event.control.value #71'sclient_state_readers_test(346 assertions),scoped_helper_test, both gem tests andrun_in_process_test.sh.compat_testandregexp_teststop at lines 67 and 132, as on main.