Skip to content

refactor: improve hand divider performance a bit#185

Merged
Apricot-S merged 4 commits intomasterfrom
optimize-performance
Feb 6, 2026
Merged

refactor: improve hand divider performance a bit#185
Apricot-S merged 4 commits intomasterfrom
optimize-performance

Conversation

@Nihisil
Copy link
Contributor

@Nihisil Nihisil commented Feb 5, 2026

Some Python related optimizations were made, algorithm remains unchanged.

Summary of changes:

  • Custom __eq__/__lt__ methods were replaced by @dataclass(frozen=True, order=True)
  • Changed _BlockType to (int, Enum) to enable comparison
  • Reordered fields to (tile_34, ty) to maintain correct sort order
  • from_meld now uses meld.type directly instead of is_chi/is_pon/is_kan
  • Added remaining count tracking to avoid sum() at terminal nodes in recursion

All 2.1kk hands in validation set processed without errors.

Benchmark results

Old

Throughput: 28443 hands/sec (based on median)
Avg per hand: 0.035ms (based on median)

New

Throughput: 29315 hands/sec (based on median)
Avg per hand: 0.034ms (based on median)

Overall profile

Metric Old New Change
Total profile time 16.603s 15.445s -7.0%
Total profile calls 74,744,352 67,800,659 -9.3%

divide_hand function

Metric Old New Change
Own time 0.368s 0.362s -1.6%
Cumulative time 5.090s 4.097s -19.5%
Callee calls 1,760,004 1,760,004 0.0%
Callee tottime 0.807s 0.780s -3.4%
Callee cumtime 4.722s 3.736s -20.9%

@Nihisil Nihisil added this to the v2.0.0 milestone Feb 5, 2026
@Nihisil Nihisil requested a review from Apricot-S February 5, 2026 15:28
@Nihisil Nihisil force-pushed the optimize-performance branch from 7bd2daa to dc9ae49 Compare February 5, 2026 15:31
@Nihisil Nihisil requested a review from Apricot-S February 5, 2026 16:03
@Nihisil Nihisil requested a review from Apricot-S February 6, 2026 00:48
Copy link
Collaborator

@Apricot-S Apricot-S left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Apricot-S Apricot-S merged commit e4dc4c5 into master Feb 6, 2026
8 checks passed
@Apricot-S Apricot-S deleted the optimize-performance branch February 6, 2026 00:54
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