Skip to content

Conversation

@juharris
Copy link
Contributor

@juharris juharris commented Aug 9, 2025

I came across this library and decided to make some very minor optimizations.

  • Avoid identity lambda which can slow down things a little bit: https://stackoverflow.com/a/22291628/1226799
  • Avoid calling the accessor function twice.
  • Use a tuple instead of list for regex.finditer
  • Sort suggestions in-place instead of making a new list.
  • Use map + operator.itemgetter(-1) instead of a generator + z[-1]

There are probably more optimizations we can do like not making tuples in suggestions as big. But that would involve a bigger refactoring.

Copy link
Owner

@amjith amjith left a comment

Choose a reason for hiding this comment

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

Very nice.

@amjith amjith merged commit eb21a8c into amjith:main Aug 10, 2025
5 checks passed
@juharris juharris deleted the opt-long-collections branch August 10, 2025 01:27
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