Files
ruby/lib/unicode_normalize
Koichi SasadaandClaude Opus 5 6ca4a12032 [Bug #22293] Make String#unicode_normalize work in non-main Ractors
UnicodeNormalize.normalize and .normalized? read three constants that are
not shareable, so any call from a non-main Ractor raised
Ractor::IsolationError:

* NF_HASH_C / NF_HASH_D, the memoization caches. They cannot be made
  shareable because a shareable Hash cannot be written to. Keep them per
  Ractor instead: normalization is deterministic, so recomputing an entry
  in another Ractor always gives the same string, and the cache is only a
  cache. The DoS bound of MAX_HASH_LENGTH now applies per Ractor.

* UNICODE_ENCODINGS, which is splatted in a `when` clause on the path for
  UTF-16, UTF-32, GB18030 and UCS-2/4BE. Freeze it.

The other constants are already shareable on master: tables.rb is
frozen_string_literal with frozen tables, and Regexp instances are frozen
since cb03bf43eb.

Keeping the caches keeps main Ractor performance: dropping them instead
costs 2.7x to 11x on real text, and asking the main Ractor for an entry
costs 19.4us per round trip against 3.8us to just compute it. The per
Ractor lookup adds about 60ns per call; normalized? fetches its cache
lazily so a string without a match does not pay it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 05:59:11 +09:00
..