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(native): Reduce chance of frame drops with InteractionManager #3127

Merged
merged 1 commit into from
Jun 22, 2024

Conversation

ntucker
Copy link
Collaborator

@ntucker ntucker commented Jun 22, 2024

Motivation

Performance feature parity with web

Solution

Add NetworkManager.idleCallback overridable method

This allows platform specific implementations by overriding the method.
For instance, on web:

import { NetworkManager } from '@data-client/core';

export default class WebNetworkManager extends NetworkManager {
  static {
    if (typeof requestIdleCallback === 'function') {
      WebNetworkManager.prototype.idleCallback = requestIdleCallback;
    }
  }
}

In React Native we use InteractionManager to implement similar functionality to requestIdleCallback:

import { NetworkManager } from '@data-client/core';
import { InteractionManager } from 'react-native';

export default class NativeNetworkManager extends NetworkManager {
  /** Calls the callback when client is not 'busy' with high priority interaction tasks
   *
   * Override for platform-specific implementations
   */
  protected idleCallback(
    callback: (...args: any[]) => void,
    options?: IdleRequestOptions,
  ) {
    InteractionManager.runAfterInteractions(callback);
    if (options?.timeout) {
      InteractionManager.setDeadline(options.timeout);
    }
  }
}

Copy link

changeset-bot bot commented Jun 22, 2024

🦋 Changeset detected

Latest commit: dcea69d

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/react Patch
@data-client/core 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: dcea69d Previous: 29c879b Ratio
normalizeLong 432 ops/sec (±1.78%) 447 ops/sec (±1.67%) 1.03
infer All 9650 ops/sec (±0.63%) 9561 ops/sec (±0.67%) 0.99
denormalizeLong 337 ops/sec (±0.98%) 346 ops/sec (±1.18%) 1.03
denormalizeLong donotcache 875 ops/sec (±0.57%) 895 ops/sec (±1.13%) 1.02
denormalizeShort donotcache 500x 1363 ops/sec (±0.18%) 1382 ops/sec (±0.16%) 1.01
denormalizeShort 500x 973 ops/sec (±0.25%) 965 ops/sec (±0.21%) 0.99
denormalizeShort 500x withCache 4753 ops/sec (±0.25%) 5049 ops/sec (±0.17%) 1.06
denormalizeLong with mixin Entity 292 ops/sec (±0.52%) 302 ops/sec (±0.32%) 1.03
denormalizeLong withCache 6086 ops/sec (±0.12%) 6199 ops/sec (±0.35%) 1.02
denormalizeLong All withCache 6359 ops/sec (±0.38%) 6591 ops/sec (±0.22%) 1.04
denormalizeLong Query-sorted withCache 6124 ops/sec (±0.84%) 6417 ops/sec (±0.76%) 1.05
denormalizeLongAndShort withEntityCacheOnly 1469 ops/sec (±0.46%) 1534 ops/sec (±0.48%) 1.04
getResponse 5804 ops/sec (±1.44%) 6011 ops/sec (±1.23%) 1.04
getResponse (null) 6195176 ops/sec (±0.89%) 6095253 ops/sec (±0.84%) 0.98
getResponse (clear cache) 287 ops/sec (±0.42%) 296 ops/sec (±0.26%) 1.03
getSmallResponse 2663 ops/sec (±0.24%) 2672 ops/sec (±0.18%) 1.00
getSmallInferredResponse 2019 ops/sec (±0.28%) 2046 ops/sec (±0.18%) 1.01
getResponse Query-sorted 5363 ops/sec (±0.69%) 6536 ops/sec (±0.67%) 1.22
getResponse Collection 6292 ops/sec (±1.04%) 6210 ops/sec (±1.55%) 0.99
get Collection 4887 ops/sec (±1.04%) 5398 ops/sec (±1.04%) 1.10
setLong 416 ops/sec (±2.24%) 444 ops/sec (±1.82%) 1.07
setLongWithMerge 177 ops/sec (±1.49%) 190 ops/sec (±1.50%) 1.07
setLongWithSimpleMerge 188 ops/sec (±1.63%) 201 ops/sec (±1.07%) 1.07
setSmallResponse 500x 847 ops/sec (±1.64%) 864 ops/sec (±1.27%) 1.02

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

@ntucker ntucker force-pushed the interactionmanager branch from f6686ff to 54426a5 Compare June 22, 2024 10:45
@ntucker ntucker force-pushed the interactionmanager branch from 54426a5 to dcea69d Compare June 22, 2024 10:49
Copy link

codecov bot commented Jun 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.79%. Comparing base (da255ba) to head (dcea69d).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3127   +/-   ##
=======================================
  Coverage   98.79%   98.79%           
=======================================
  Files         125      127    +2     
  Lines        2232     2238    +6     
  Branches      452      453    +1     
=======================================
+ Hits         2205     2211    +6     
  Misses         16       16           
  Partials       11       11           

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

@ntucker ntucker merged commit c18fbf7 into master Jun 22, 2024
26 checks passed
@ntucker ntucker deleted the interactionmanager branch June 22, 2024 11:02
@github-actions github-actions bot mentioned this pull request Jun 22, 2024
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