Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce iterations in concatenate! #946

Merged
merged 1 commit into from
Jan 10, 2024

Conversation

ekaitz-zarraga
Copy link
Contributor

@ekaitz-zarraga ekaitz-zarraga commented Jan 9, 2024

This commit should reduce the amount of iterations in concatenate to N where N is the sum of the lengths of the input lists.

The previous implementation iterated from the beginning in each concatenation because of last-pair.

This implementation is significantly faster in this extreme case:

(concatenate! `(,(iota 50000) ,@(map list (iota 500))))

Previous implementation:
real 0m0.671s
user 0m0.658s
sys 0m0.013s

This implementation:
real 0m0.175s
user 0m0.174s
sys 0m0.001s

The tests is done using time, which is not reliable at all, but using (trace last-pair) shows accurately what happens with the iterations.

This commit should reduce the amount of iterations in concatenate to N
where N is the sum of the lengths of the input lists.

The previous implementation iterated from the beginning in each
concatenation because of `last-pair`.

This implementation is significantly faster in this extreme case:

(concatenate! `(,(iota 50000) ,@(map list (iota 500))))

>> Previous implementation:
real	0m0.671s
user	0m0.658s
sys	0m0.013s

>> This implementation:
real	0m0.175s
user	0m0.174s
sys	0m0.001s

The tests is done using `time`, which is not reliable at all, but using
`(trace last-pair)` shows accurately what happens with the iterations.
Copy link
Owner

@ashinn ashinn left a comment

Choose a reason for hiding this comment

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

Thanks!

@ashinn ashinn merged commit 97a04bd into ashinn:master Jan 10, 2024
3 checks passed
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