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

Avoid creating threads when dispatching tasks #1496

Merged
merged 5 commits into from Nov 24, 2023

Conversation

tonidero
Copy link
Contributor

Description

We were creating threads every time we added a task to the executor service. This shouldn't be a problem if tasks ended early and not too many tasks were in the queue, but it's not very efficient. This is another implementation to propagate exceptions to the main thread so they can be thrown and not swallowed when they happen on the thread pool.

@tonidero tonidero added the perf A code change that improves performance label Nov 24, 2023
Copy link

codecov bot commented Nov 24, 2023

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (a2b6e7b) 84.12% compared to head (6b90058) 84.13%.
Report is 1 commits behind head on main.

Files Patch % Lines
...tlin/com/revenuecat/purchases/common/Dispatcher.kt 63.63% 4 Missing ⚠️
...otlin/com/revenuecat/purchases/PurchasesFactory.kt 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1496   +/-   ##
=======================================
  Coverage   84.12%   84.13%           
=======================================
  Files         215      215           
  Lines        7193     7197    +4     
  Branches     1016     1016           
=======================================
+ Hits         6051     6055    +4     
- Misses        741      742    +1     
+ Partials      401      400    -1     

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

} catch (@Suppress("TooGenericExceptionCaught") e: Exception) {
errorLog("Exception running command: $e")
mainHandler?.post {
throw e.cause ?: e
Copy link
Contributor

Choose a reason for hiding this comment

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

can you explain this? why not just throw e?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably not needed, I was mostly copying here what we had previously... In my tests, the cause was sometimes null, so I fallback to the original exception, but we could probably just propagate the original exception

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I am not sure why we were doing e.cause 🤔

@tonidero tonidero marked this pull request as ready for review November 24, 2023 12:13
@tonidero tonidero requested a review from a team November 24, 2023 12:19
@tonidero tonidero merged commit b4cd7d2 into main Nov 24, 2023
9 checks passed
@tonidero tonidero deleted the avoid-creating-threads-dispatcher-tasks branch November 24, 2023 13:10
tonidero pushed a commit that referenced this pull request Nov 30, 2023
**This is an automatic release.**

### Bugfixes
* Fix white line around buttons in Template 4 (#1499) via Cesar de la
Vega (@vegaro)
### Performance Improvements
* Avoid creating threads when dispatching tasks (#1496) via Toni Rico
(@tonidero)
### Other Changes
* Refactor QueryPurchasesUseCase and adds QueryPurchasesByTypeUseCase
(#1495) via Cesar de la Vega (@vegaro)
* Fixes on `update_snapshots_repo` (#1501) via Cesar de la Vega
(@vegaro)
* Fixes on generate_snapshots_RCUI lane (#1500) via Cesar de la Vega
(@vegaro)
* Fix integration tests (#1498) via Toni Rico (@tonidero)
* Cleanup warnings in AcknowledgePurchaseUseCaseTest (#1497) via Cesar
de la Vega (@vegaro)
* Add AcknowledgePurchaseUseCase (#1492) via Cesar de la Vega (@vegaro)
* Refactor findPurchaseInPurchaseHistory (#1493) via Cesar de la Vega
(@vegaro)
* ConsumePurchaseUseCase (#1487) via Cesar de la Vega (@vegaro)
* Add retries with backoff and different treatment to
SERVICE_UNAVAILABLE (#1490) via Cesar de la Vega (@vegaro)

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf A code change that improves performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants