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

ConcurrentMappingIterable: introduce futuretools.FutureResultCollection to optimize FDFO concurrent mapping (closes #20) #21

Merged
merged 5 commits into from
Sep 30, 2024

Conversation

ebonnal
Copy link
Owner

@ebonnal ebonnal commented Sep 30, 2024

Optimize First Done First Out aka unordereded mapping.

Removes the overhead of using futures waiting functions (asyncio.wait(..., FIRST_COMPLETED) or concurrent.futures.wait(..., FIRST_COMPLETED)) that register and remove waiters/callbacks for all futures for each next.

@ebonnal ebonnal added the optimization Optimize performances label Sep 30, 2024
@codecov-commenter
Copy link

codecov-commenter commented Sep 30, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (562c6b8) to head (18fd582).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #21   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           13        14    +1     
  Lines         1198      1248   +50     
=========================================
+ Hits          1198      1248   +50     
Flag Coverage Δ
100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ebonnal
Copy link
Owner Author

ebonnal commented Sep 30, 2024

fyi @erezsh 👁️

Copy link
Contributor

@erezsh erezsh left a comment

Choose a reason for hiding this comment

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

Overall looks good to me.

I added a couple of style comments that you're welcome to ignore.

self._results.put(future.result())

def add_future(self, future: "Future[T]") -> None:
future.add_done_callback(lambda f: self._done_callback(f))
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just:

 future.add_done_callback(self._done_callback)

Copy link
Owner Author

Choose a reason for hiding this comment

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

nice catch! (no reason, I dragged this lambda from previous iterations 🤦🏻)

# wait, queue, yield
while future_results:
result = next(future_results)
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be a little bit cleaner with with suppress(StopIteration): ...

Also applies to the except above, by putting it outside the while.

Copy link
Owner Author

@ebonnal ebonnal Sep 30, 2024

Choose a reason for hiding this comment

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

Oh great!

@ebonnal ebonnal merged commit 58c886c into main Sep 30, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Optimize performances
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants