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

Feat transform iterator #50

Closed
wants to merge 6 commits into from

Conversation

jeswr
Copy link
Collaborator

@jeswr jeswr commented Mar 26, 2022

Per discussion in #44 - a fast transform iterator that uses mutations. Happy to take suggestions for renaming.

Could be a separate file though (and maybe we could also split the code into more separate files in general).

@RubenVerborgh This requires modifying some of the package.json and tsconfig.json settings. So it may be better to do this in a separate PR.

This code could probably do with some more integration tests in the future - but not sure if it is worth bothering until the changes in #45 get integrated.

Pinging @jacoscaz

@coveralls
Copy link

coveralls commented Mar 26, 2022

Coverage Status

Coverage remained the same at 100.0% when pulling 3403220 on jeswr:feat/fast-transform-iterator into 7a089e3 on RubenVerborgh:main.

@jeswr
Copy link
Collaborator Author

jeswr commented Mar 26, 2022

I tried to add some features for throwing extra errors/warnings in production mode in 3a57d17 - but I couldn't quite figure out how to configure the configs and test-suite properly to handle this.

@RubenVerborgh
Copy link
Owner

@jeswr Thanks! Do we have any insights into the performance of this one?

Copy link
Owner

@RubenVerborgh RubenVerborgh left a comment

Choose a reason for hiding this comment

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

So I like the idea, but I think mutation unnecessarily complicates things.

Suggestion: can we instead override map and filter methods on the original TransformIterator, with a check that if the source already is instanceof TransformIterator that we create this more optimized iterator instead?

For instance, source.map(x => x * 2).map(y => y + 1). Then the second map recognizes that the input is already a TransformIterator, so what it actually returns is a TransformIterator over source (!) with as map function the combination of the two mappings. So basically source.map(combine(x => x * 2, y => y + 1)).

}

read(): T | null {
const func = build(this.transforms);
Copy link
Owner

Choose a reason for hiding this comment

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

We can cache this instead.

Transforms items according to a synchronous generator (hence no need for buffering)
@param {Function} transform The function to transform items with
*/
syncTransform<D>(transform: (item: T) => Generator<D>): FastTransformIterator<D> {
Copy link
Owner

Choose a reason for hiding this comment

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

What are the use cases for this transformation? Is this just a multimap?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep!

@jeswr
Copy link
Collaborator Author

jeswr commented Mar 26, 2022

@jeswr Thanks! Do we have any insights into the performance of this one?

On the experiments I did I saw up to a 2x improvement in some of the tests I did a few days ago when compared to the chained use of MapIterator and FilterIterator (I haven't done benchmarks for the transform). I'd imagine that the performance increase is somewhat proportional to the number of elements you are filtering out as well since this essentially eliminates any upstream reads that would have been made in these cases.

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.

3 participants