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

enhance: Add garbage collection based on expiry time #3343

Merged
merged 8 commits into from
Jan 6, 2025
Merged

enhance: Add garbage collection based on expiry time #3343

merged 8 commits into from
Jan 6, 2025

Conversation

ntucker
Copy link
Collaborator

@ntucker ntucker commented Jan 4, 2025

Fixes #3240

Motivation

Clean memory for long running applications

Solution

  • Ref count (aka smart pointers) based on data-binding hooks with countRef()
  • Manager that checks 0 count items that are expired every 5min to clean them
  • useQuery GCs
  • integration testing with jest timers
    • switch from list view to detail view; jest time pass to trigger sweep but not expired; view list again and it instantly renders; go back to detail view; jest time pass to expiry; re-render detail view to make sure it still renders; visit list view and see suspense fallback
  • configurable expire -> release time
  • Allow configuration options to be set at DataProvider
  • Support React Native low level scheduler
  • add initManager() to abstract lifecycle handling from framework implementation

Open Questions

  • what is the performance impact of refcounting?
  • what types of customization for gc policy should we support?

Copy link

changeset-bot bot commented Jan 4, 2025

🦋 Changeset detected

Latest commit: c94c83f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@data-client/core Patch
@data-client/react Patch
example-benchmark Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: c94c83f Previous: af07e7a Ratio
normalizeLong 499 ops/sec (±0.80%) 507 ops/sec (±0.26%) 1.02
infer All 8849 ops/sec (±1.38%) 8891 ops/sec (±1.36%) 1.00
denormalizeLong 234 ops/sec (±3.01%) 266 ops/sec (±2.47%) 1.14
denormalizeLong donotcache 871 ops/sec (±0.38%) 837 ops/sec (±0.29%) 0.96
denormalizeShort donotcache 500x 1356 ops/sec (±0.30%) 1333 ops/sec (±0.29%) 0.98
denormalizeShort 500x 764 ops/sec (±2.08%) 770 ops/sec (±2.37%) 1.01
denormalizeShort 500x withCache 4738 ops/sec (±0.54%) 4820 ops/sec (±0.88%) 1.02
denormalizeLong with mixin Entity 245 ops/sec (±1.86%) 251 ops/sec (±1.90%) 1.02
denormalizeLong withCache 6868 ops/sec (±0.31%) 7533 ops/sec (±0.27%) 1.10
denormalizeLong All withCache 6218 ops/sec (±0.40%) 6399 ops/sec (±0.21%) 1.03
denormalizeLong Query-sorted withCache 5972 ops/sec (±0.80%) 6328 ops/sec (±0.40%) 1.06
denormalizeLongAndShort withEntityCacheOnly 1562 ops/sec (±0.67%) 1623 ops/sec (±0.43%) 1.04
getResponse 6162 ops/sec (±1.16%) 6049 ops/sec (±1.40%) 0.98
getResponse (null) 4776617 ops/sec (±0.49%) 5488573 ops/sec (±0.42%) 1.15
getResponse (clear cache) 239 ops/sec (±2.05%) 248 ops/sec (±1.93%) 1.04
getSmallResponse 2528 ops/sec (±0.21%) 2710 ops/sec (±0.28%) 1.07
getSmallInferredResponse 1925 ops/sec (±0.87%) 2051 ops/sec (±0.19%) 1.07
getResponse Query-sorted 6592 ops/sec (±0.41%) 6376 ops/sec (±0.76%) 0.97
getResponse Collection 6353 ops/sec (±1.17%) 7040 ops/sec (±1.31%) 1.11
get Collection 4996 ops/sec (±0.92%) 6235 ops/sec (±0.43%) 1.25
setLong 506 ops/sec (±0.58%) 494 ops/sec (±0.51%) 0.98
setLongWithMerge 192 ops/sec (±0.89%) 195 ops/sec (±0.35%) 1.02
setLongWithSimpleMerge 205 ops/sec (±0.41%) 205 ops/sec (±0.36%) 1
setSmallResponse 500x 906 ops/sec (±0.26%) 890 ops/sec (±1.66%) 0.98

This comment was automatically generated by workflow using github-action-benchmark.

@ntucker ntucker force-pushed the gc branch 2 times, most recently from 67752cc to 90e2adf Compare January 4, 2025 11:13
Copy link

codecov bot commented Jan 4, 2025

Codecov Report

Attention: Patch coverage is 96.49123% with 4 lines in your changes missing coverage. Please review.

Project coverage is 98.77%. Comparing base (060d8e1) to head (c94c83f).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
packages/core/src/state/GCPolicy.ts 93.54% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3343      +/-   ##
==========================================
- Coverage   98.85%   98.77%   -0.08%     
==========================================
  Files         132      138       +6     
  Lines        2274     2374     +100     
  Branches      466      484      +18     
==========================================
+ Hits         2248     2345      +97     
- Misses         13       15       +2     
- Partials       13       14       +1     

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

Fix code scanning alert no. 81: Prototype-polluting assignment

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

Revert "Fix code scanning alert no. 81: Prototype-polluting assignment"

This reverts commit 848b4981b3c563c2bb0e5e7bcc47d39001bf083d.
@ntucker ntucker force-pushed the gc branch 2 times, most recently from b5297c1 to ae4add3 Compare January 4, 2025 18:16
@ntucker ntucker requested a review from notwillk January 4, 2025 18:17
@ntucker ntucker force-pushed the gc branch 4 times, most recently from 358c9ec to 626738f Compare January 4, 2025 22:52
@ntucker ntucker force-pushed the gc branch 4 times, most recently from 61a0ffb to 43bccb5 Compare January 5, 2025 15:49
@ntucker ntucker force-pushed the gc branch 2 times, most recently from 8ff9d0b to 8159758 Compare January 5, 2025 16:00
@ntucker ntucker marked this pull request as ready for review January 5, 2025 16:00
@ntucker ntucker force-pushed the gc branch 2 times, most recently from cbda856 to bd56d4e Compare January 5, 2025 16:24
@ntucker ntucker merged commit 1df829e into master Jan 6, 2025
23 checks passed
@ntucker ntucker deleted the gc branch January 6, 2025 09:37
@github-actions github-actions bot mentioned this pull request Jan 6, 2025
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.

1 participant