Skip to content

Make IsTrivial() constant time - #1605

Merged
roozbehp merged 1 commit into
mainfrom
roozbehp-istrivial
Oct 13, 2026
Merged

roozbehp merged 1 commit into
mainfrom
roozbehp-istrivial

Conversation

@roozbehp

Copy link
Copy Markdown
Contributor

This is mathematically equivalent, and makes list-unicodeset.jsp result for [:L:] 39x faster, changing from 16s to 0.4s on my local benchmark. It also vastly reduces temporary memory allocations.

  • Approver: Feel free to merge on my behalf
    • rebase & merge one or more commits
    • squash & merge multiple commits into one

This is mathematically equivalent, and makes list-unicodeset.jsp result for
`[:L:]` 39x faster, changing from 16s to 0.4s on my local benchmark. It
also vastly reduces temporary memory allocations.
@roozbehp

Copy link
Copy Markdown
Contributor Author

@eggrobin, here's an analysis of why isTrivial() was slowing things down. The call sequence is/was:

  1. list-unicodeset.jsp called UnicodeJsp.showSet().
  2. That called UnicodeUtilities.showSetMain(), then UnicodeUtilities.showSet().
  3. Inside its character loop, showSet() resolved the four properties in Resolve some properties outside the loop in UnicodeUtilities.java #1606 for every character.
  4. Each XPropertyFactory.getProperty(alias) called VersionedProperty.forJSPs(...).set(alias).
  5. VersionedProperty.set() called property.isTrivial() twice for these properties.

The two calls came from these conditions:

if ((property == null && TOOL_ONLY_PROPERTIES.contains(xPropertyName))
        || (property != null && property.isTrivial() && allowRetroactive)) {
    ...
}
if (property == null || property.isTrivial()) {
    ...
}

The first condition evaluated isTrivial() even when allowRetroactive was false (fix in #1606). The second condition evaluated it again.

For the benchmark’s 158,172 letters, the grouping loop alone therefore caused:

  • 632,688 property resolutions: four per character.
  • 1,265,376 isTrivial() calls: two per resolution.

Fetching character names added another path: CodePointShower.showCodePoint() called showString(), which called UnicodeUtilities.getName(), which resolved "Name" through that same factory. The benchmark’s raw Name map contained about 52,000 ranges, making those repeated checks particularly expensive.

@roozbehp
roozbehp merged commit e2c5e74 into main Oct 13, 2026
24 checks passed
@roozbehp
roozbehp deleted the roozbehp-istrivial branch October 13, 2026 21:57
roozbehp added a commit that referenced this pull request Oct 13, 2026
)

Also:
- Resolve development properties only if showDevProperties is true
- Check allowRetroactive before calling property.isTrivial() in
  VersionedProperty.java

This further improves the speed of list-unicodeset.jsp resolution for [:L:]
by 4x on top of #1605.
Without #1605 applied, it
improves the speed of the above resolution by 6x.

It also reduces temporary memory allocations by about 90%.
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