Skip to content

⚡ Build each transliteration table once instead of on every call - #1110

Merged
rathesDot merged 1 commit into
mainfrom
cache-notation-maps
Oct 23, 2026
Merged

rathesDot merged 1 commit into
mainfrom
cache-notation-maps

Conversation

@rathesDot

Copy link
Copy Markdown
Member

transliterate rebuilt its lookup table on every call, spreading the object once per letter, so the cost grew with the square of the table. With 0.9.0's 78 Grantha rows, a call takes about twice as long as before. Measured with 20,000 calls of getRomanization('பாடசாலைக்கு'):

Version Per call
0.8.1 ~915 µs
0.9.0 ~1,835 µs
this change ~1 µs

This showed up on learn-tamil.com: a unit test that builds a 1,000-word dictionary passed the 5-second limit after upgrading to 0.9.0, and every page build calls these functions many times.

Change

The table is built once per notation and Grantha setting, and then reused. Output is unchanged. A new test switches between { grantha: false } and the default to check the cached tables stay apart.

Output doesn't change, so I'd release this as 0.9.1 (patch).

Checks

pnpm test (9 passed, snapshots unchanged), pnpm eslint, pnpm tsc --noEmit and pnpm format --check all pass.

Every call rebuilt the lookup table by spreading an object per letter,
about 1.8 ms per call since the Grantha rows were added. The tables are
now built once per notation and Grantha setting: about 1 µs per call.
@rathesDot
rathesDot merged commit e92d622 into main Oct 23, 2026
4 checks passed
@rathesDot
rathesDot deleted the cache-notation-maps branch October 23, 2026 10:57
@rathesDot rathesDot mentioned this pull request Oct 23, 2026
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