Skip to content

performance: faster equality operation - #355

Open
ClementBeal wants to merge 3 commits into
schultek:mainfrom
ClementBeal:performance/faster-equality
Open

ClementBeal wants to merge 3 commits into
schultek:mainfrom
ClementBeal:performance/faster-equality

Conversation

@ClementBeal

@ClementBeal ClementBeal commented Sep 9, 2026 •

Copy link
Copy Markdown

I was looking at the following benchark and I was surprised by the slowness of dart_mappable compared with the other packages during their tests of indexOf() and ==.

I have run the very same benchark before and after my changes and I have measured a 50% improvement on both the indexOf() and == benchmarks.

Three changes:

  • The every() method creates a callback that is invoked for each item of the iterable. This is not really a problem for small lists, but on a hot path it starts to become noticeably slower because of the callback overhead. We can already make it faster by simply using a for loop. It is slightly less compact, though -> around 15% faster
  • When comparing two objects of the exact same runtime type, we still resolve their base types through type_plus before comparing their fields. This lookup is unnecessary when both runtime types are already equal. Adding a fast path avoids this work while preserving the existing behavior for different generic runtime types -> around 35% faster
  • Something that is already done with _mapperForType. We avoid to get twice the same mapper. -> another 10%

@ClementBeal
ClementBeal marked this pull request as ready for review September 9, 2026 17:12
@parlough

Copy link
Copy Markdown

@schultek I think it'd be nice to land this optimization :D

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