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

optimize Zip to only use one Pull, and test for coverage #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dr2chase
Copy link
Contributor

Pull is expensive, even with the coroutine patch. Only one is necessary.

Copy link
Owner

@DeedleFake DeedleFake left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I have a few comments, but overall very nice. That should be quite a bit more efficient. Kind of makes me wonder if some API could be added at some point to convert a pull iterator back into its push equivalent for the remainder of the items so that it could be used in the case that seq2 continues after seq1 finishes.

transform.go Outdated
@@ -99,7 +99,7 @@ type Zipped[T1, T2 any] struct {

// Zip returns a new Seq that yields the values of seq1 and seq2
// simultaneously.
func Zip[T1, T2 any](seq1 Seq[T1], seq2 Seq[T2]) Seq[Zipped[T1, T2]] {
func Zip2Pull[T1, T2 any](seq1 Seq[T1], seq2 Seq[T2]) Seq[Zipped[T1, T2]] {
Copy link
Owner

Choose a reason for hiding this comment

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

If the new one is completely identical to the old one in terms of functionality, there's no reason to keep the old one around, too. If they're different, the godoc comments should explain how. If you want to keep it for benchmarking purposes, move it into a _test.go file like oldZip().

oldzip_test.go Outdated
@@ -3,6 +3,7 @@ package xiter
import "testing"

func BenchmarkOldZip(b *testing.B) {
b.ReportAllocs()
Copy link
Owner

Choose a reason for hiding this comment

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

Is there any particular reason to use this instead of just passing -benchmem to go test?

transform.go Outdated
// Zip returns a new Seq that yields the values of seq1 and seq2
// simultaneously.
func Zip[T1, T2 any](seq1 Seq[T1], seq2 Seq[T2]) Seq[Zipped[T1, T2]] {
return func(body func(Zipped[T1, T2]) bool) {
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not thrilled with body as the name of the yield function. Why not just yield like everywhere else?

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