Performance improvements#1337
Merged
Merged
Conversation
chrisrink10
commented
May 10, 2026
| from itertools import batched | ||
|
|
||
| def partition(coll: Sequence[T], n: int) -> Iterable[tuple[T, ...]]: | ||
| return batched(coll, n) |
Member
Author
There was a problem hiding this comment.
Batched is written in C, so should be much faster. I noticed partition dropped out of the top own-time function calls once I switched this so 🤞 this should help improve performance for versions of Python 3.12+.
| ) -> None: | ||
| self._first = first | ||
| self._rest = Maybe(seq).or_else_get(EMPTY) | ||
| self._rest = EMPTY if seq is None else seq |
Member
Author
There was a problem hiding this comment.
I think this extra allocation and method call was adding a lot of overhead to just creating a new Cons cell, which happens quite frequently. This simple check should be a bit faster.
Member
Author
There was a problem hiding this comment.
Creating new NodeEnv nodes recursively is expensive. Making the type mutable and mutating it should vastly reduce the performance impact of this method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
itertools.batched(which is written in C) for Python 3.12+ replacingbasilisp.lang.util.partition.Maybeobjects in the constructor ofConscells, since a simpleifexpression check would suffice.NodeEnvtypes mutable, reducing the amount of new object creation viaattrs.evolvethat needs to happen at compile time for new AST nodes.