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 ArrayIterator #38

Closed
jeswr opened this issue Feb 20, 2022 · 5 comments
Closed

Optimize ArrayIterator #38

jeswr opened this issue Feb 20, 2022 · 5 comments

Comments

@jeswr
Copy link
Collaborator

jeswr commented Feb 20, 2022

It currently uses .shift which is a O(n) operation. So it costs O(n^2) to iterator over.

@jeswr
Copy link
Collaborator Author

jeswr commented Feb 21, 2022

The BufferedIterator will also suffer similar performance issues when the maxBufferSize, as does the MultiTransformer with a large transformerQueue.

@RubenVerborgh
Copy link
Owner

All major JavaScript engines implement behavior that is closer to O(1), see:

Trying to be faster ourselves will most likely have the opposite effect.

@RubenVerborgh
Copy link
Owner

Given the discussion in #44, we might want to see if alternatively implementations (notably a linked list) would speed this up.

@jacoscaz
Copy link
Collaborator

@RubenVerborgh interesting you should say that... I thought exactly the same, and came up with https://github.com/jacoscaz/AsyncIterator/blob/42311b68988a971fc072c896100d7082b4162470/asynciterator.ts#L744-L783 . I'm still testing it. Interested in a PR?

@RubenVerborgh
Copy link
Owner

That's quite perfect and exactly what I had in mind!
Curious about perf; PR welcome!

(Nit: perhaps we should have that code in a separate file and include it.)

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

No branches or pull requests

3 participants