Skip to content

Remove recursion from collapse#796

Merged
bbayles merged 5 commits intomore-itertools:masterfrom
james-wasson:collapse-improvement
Jan 12, 2024
Merged

Remove recursion from collapse#796
bbayles merged 5 commits intomore-itertools:masterfrom
james-wasson:collapse-improvement

Conversation

@james-wasson
Copy link
Copy Markdown
Contributor

@james-wasson james-wasson commented Jan 9, 2024

Issue reference

#799

Changes

Change collapse to remove the recursion resulting in noticeable speedup.

Before:
image
After:
image

@james-wasson james-wasson changed the title Remove recursion from the collapse method Remove recursion from the collapse Jan 9, 2024
@james-wasson james-wasson changed the title Remove recursion from the collapse Remove recursion from collapse Jan 9, 2024
@james-wasson
Copy link
Copy Markdown
Contributor Author

Not sure why this build is failing for version 3.8. Does anyone have any suggestions on how to get this fixed? Thx!

@haukex
Copy link
Copy Markdown
Contributor

haukex commented Jan 10, 2024

@james-wasson Looks like the build is failing on the black step; you'll need to reformat your files with black. You can run all the checks locally with make all-checks.

@bbayles
Copy link
Copy Markdown
Collaborator

bbayles commented Jan 10, 2024

I'd rather have a non-recursive algorithm, so once this passes checks I'll merge it! Thanks for the PR.

@james-wasson
Copy link
Copy Markdown
Contributor Author

All checks passed locally.

@elliotwutingfeng
Copy link
Copy Markdown
Contributor

For reference

from more_itertools import collapse, consume
iterable = ['ab', ('cd', [(1, 2), ([3, [(1, 2), ([3, 4], [[5], [6]])]], [[5], [6]])]), ['gh', 'ij'], [(1, [(1, 2), ([3, 4], [[5], [6]])])]]
%timeit -n 100000 consume(collapse(iterable))

@bbayles bbayles merged commit 419e524 into more-itertools:master Jan 12, 2024
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.

4 participants