Giter Club home page Giter Club logo

react-native-jsi-contacts's Introduction

react-native-jsi-contacts

The current react-native-contacts library uses the React Native Bridge to convert the native Java/Objective-C types to JavaScript values. This is asynchronous, batched, and serializes the huge contacts list in the native world (write into WritableArray/WritableMap, then let the Bridge convert to JSON), then deserializes it on the JavaScript side using JSON. It is therefore slow.

react-native-jsi-contacts uses JSI to be way faster.

  • Direct invocation (no batching!)
  • No JSON serialization happening
  • Directly convert object into JSI Types
  • Lazily get individual Contact fields (jsi::HostObject lazy-get)

โš ๏ธ react-native-jsi-contacts only works on Android. If you want me to implement iOS support, consider funding the project.

Performance

The library uses almost the same native "getContacts()" function as react-native-contacts (minor tweaks to not use the Bridge types WritableArray/WritableMap), so the only difference is the conversion speed.

For 25 contacts, I have measured an average speed increase of ~35%, this greatly scales with the amount of contacts you have though.

 LOG  JSI: Contacts Permission: granted
 LOG  JSI: Got: 25 contacts in 55.14947900176048ms.
 LOG  Bridge: Contacts Permission: granted
 LOG  Bridge: Got: 25 contacts in 74.15260401368141ms.

For 25 contacts, the conversion between the native Java Contacts list and the JavaScript Contacts list takes only ~3 milliseconds!

Installation

  1. Install using npm/yarn

    npm install react-native-jsi-contacts
  2. Add this code:

    JsiContactsModule.install(reactApplicationContext);

    to your JSIModulePackage's getJSIModules method. See the react-native-mmkv installation guide on how to create a JSIModulePackage.

Sponsors

This project is sponsored by Galaxycard.

Usage

Get a list of all contacts:

import { getContactsAsync } from "react-native-jsi-contacts";

const contacts = await getContactsAsync();

Get a hashsum to compare for any changes in the contact book:

import { getHashAsync } from "react-native-jsi-contacts";
import { MMKV } from "react-native-mmkv";

const storage = new MMKV();

const hash = await getHashAsync();
const previousHash = storage.getString("contactsHash")
if (previousHash !== hash) {
  // get all contacts and reload hash now.
}

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

Thanks

  • Thanks to GalaxyCard for sponsoring this project
  • Thanks to react-native-contacts for the native "getContacts()" implementation

react-native-jsi-contacts's People

Contributors

mrousavy avatar bryansum avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.