-
Notifications
You must be signed in to change notification settings - Fork 586
Feature - #551 - Clearing History Via Isolate #604
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
Feature - #551 - Clearing History Via Isolate #604
Conversation
Let me know when this PR is ready for review.
...Clear-History-via-Isolate-Compute
My Findings...
Local Database Hive do not support concurrent connections or transactions due to Native OS locking the hive files on the user desired directory, (hive.lock) files.
- Linux Based Arch Distributions and Apple System follow strict file lock system and wouldn't allow opening or accessing boxes from multiple isolates.
Reasoning
Hive.initandhive.initFlutterare both method-channel and main UI thread operations which needs many data accessibility which are only available in main thread isolate.
Cheap Work Around Solution
- Close Hive in the main thread
- Start an isolate
- Initialize Hive in that isolate
- Offload tasks to new isolate & Close Hive
- Re-Open Hive Box in the main thread
Problems
- Although the database transactions are fast, there are high chances the database behavior becomes highly unpredictable.
- The cleaning service job trigger logic had to changed, since calling it main function may become stupidity.
Technical Issues
- With issues stated, frequent switches between threads will make too many open/close hive boxes to hinder performance of the app.
- App may stop working abruptly
- IOS Production app may not allow these operations to do so, and may kill the app.
- The Hive documentation clearly states that it is not designed for multi-threaded use.
- Simultaneous reads/writes across isolates may lead to inconsistencies.
What about... PR 604
- The reason why it could have worked for Android, is due to its lenient OS behavior although its Linux-based distribution.
- Even though Android doesn't throw an error, it's still not safe to open Hive in multiple isolates.
Note
- There is another database called 'Isar' which probably supports multi-threaded concurrent transactions which could have been possible to resolve this functionality.
Conclusion
- The issue opened is very real but the way it has to be tackled is just to clear them in main isolate using optimization techniques like batch request, clearing history in frequent intervals and few more everything in Main Thread ONLY.
cc: @ashitaprasad
To be reviewed by @DenserMeerkat
@ashitaprasad
The stated alternate solution works 👍, but I couldn't find a way to check & compare performance differences with the batching.
I believe the 5 seconds retention period can be removed and the PR title can be renamed to match the solution used.
Uh oh!
There was an error while loading. Please reload this page.
Foss Hack 2025 - Clear History Via Isolate
Use of dynamic switch logic to determine the use of [Compute] function and [Isolate] function to Clear History during the app launch.
Team Dart Knight
Vishwa Karthikvishwa.prarthana@gmail.comRelevant PR for Clearing API History
Debug Considerations
Checklist
mainbranch before making this PRflutter upgradeand verify)flutter test) and all tests are passingAdded/updated tests?
We encourage you to add relevant test cases.
OS on which you have developed and tested the feature?
cc: @ashitaprasad