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

performance: Use upstream optimizations #15

Open
jeswr opened this issue Mar 29, 2022 · 3 comments
Open

performance: Use upstream optimizations #15

jeswr opened this issue Mar 29, 2022 · 3 comments

Comments

@jeswr
Copy link
Member

jeswr commented Mar 29, 2022

In light of upstream changes we should avoid using the SimpleTransformIterator here to be able to take full advantage of them
@jacoscaz @rubensworks

@jeswr
Copy link
Member Author

jeswr commented Mar 31, 2022

Moreover - I think it should look something like

import { AsyncIterator } from 'asynciterator';

export class NestedLoopJoin<D, T> implements AsyncIterator<T> {
  private source: AsyncIterator<T>;
  constructor(left: AsyncIterator<D>, private right: AsyncIterator<D>, join: (left: D, right: D) => T) {
    this.source = union(left.map(leftElem => right.clone().mapFilter(rightElem => join(leftElem, rightElem))));
  }
  read() {
    return this.source.read();
  }
  close() {
    this.source.close();
    this.right.close();
  }
  // Closing still needs to be handled so
}

export class DynamicNestedLoopJoin<D, T> implements AsyncIterator<T> {
  constructor(left: AsyncIterator<D>, right: (elem: D) => AsyncIterator<D>, join: (left: D, right: D) => T) {
    return union(left.map(leftElem => right(leftElem).mapFilter(rightElem => join(leftElem, rightElem))));
  }
}

where mapFilter (possibly better called maybeMap) differs from the current implementation of map in that it filters out null values,

@rubensworks
Copy link
Member

Pinging @joachimvh as well, since he may have some insights on this as well.

@joachimvh
Copy link
Member

Pinging @joachimvh as well, since he may have some insights on this as well.

I don't remember much about the code here, but they're simple classes so not that much you can do wrong I think. The code above looks fine at a first glance.

Returning from a constructor is interesting though, didn't know you could do that. Would that break an instanceof call? Is there any difference to extending UnionIterator and doing a super call?

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