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

feat: V3 🫴 #656

Merged
merged 96 commits into from
Apr 30, 2024
Merged

feat: V3 🫴 #656

merged 96 commits into from
Apr 30, 2024

Conversation

mrousavy
Copy link
Owner

@mrousavy mrousavy commented Mar 25, 2024

V3

react-native-mmkv V3 brings a ton of new features! 🥳

Bridgeless TurboModule

react-native-mmkv is now a bridgeless C++ TurboModule.

This means, there is no more Java or Objective-C code required for module initialization, everything is handled synchronously on the JS thread.

react-native-mmkv already was a JSI module before, so the performance improvements are only marginal.

But the codebase is now shared across iOS and Android, so the implementation is no longer duplicated! 🥳

New APIs: trim() and size

V3 adds two new APIs to react-native-mmkv:

  • trim(): Trim a MMKV storage unit. This can be called after deleting a bunch of keys (as deletions don't resize the storage), or when receiving a memory warning by the OS. You don't need to call this though.
  • size: Gets the current actual size of the storage unit, in bytes.

Example:

const storage = new MMKV()
if (storage.size >= 400) {
  storage.trim()
}

New config option: mode

A new option has been added to the MMKV constructor: mode.

mode can be one of two values:

  • Mode.SINGLE_PROCESS: The MMKV instance is only used from a single process (this app).
  • Mode.MULTI_PROCESS: The MMKV instance may be used from multiple processes, such as app clips, share extensions or background services.

Example:

const storage = new MMKV({
  id: 'shared-storage',
  mode: Mode.MULTI_PROCESS
})

Buffer improvements

The Buffer APIs have improved.

  1. Instead of Uint8Array, getBuffer(...) and set(.., buffer) now use ArrayBuffer as a type. If you want to write Uint8's, you can still use new Uint8Array(arrayBuffer), but ArrayBuffer is the way to go in most cases.
  2. Performance improvements: The buffer APIs got much faster in 3 locations:
    1. ArrayBuffer is faster to use than Uint8Array/TypedArray
    2. set(key, buffer) now performs one less copy, which could yield huge performance improvements when working with larger buffers.
    3. getBuffer(...) now performs one less copy, which could yield huge performance improvements when working with larger buffers.

MMKV Core on iOS

Since react-native-mmkv V3 is now a cross-platform C++ TurboModule (or xplat/"CxxTurboModule"), we are also now using MMKV-Core instead of MMKV-iOS for the iOS codebase.

For simple values (such as numbers or booleans) this now uses C++ directly, instead of going through Objective-C/NSObjects. This could potentially lead to another performance gain.


Note: react-native-mmkv V3 requires react-native 0.74 or higher, and requires the new architecture (TurboModules/CodeGen) to be enabled.

For the sake of simplicity, there will be no backwards compatibility for old architecture (bridge), or RN <0.73.

@mrousavy mrousavy marked this pull request as draft March 25, 2024 09:59
Copy link

github-actions bot commented Mar 25, 2024

yarn.lock changes

Summary

Status Count
ADDED 50
UPDATED 94
DOWNGRADED 50
REMOVED 43
Click to toggle table visibility
Name Status Previous Current
@aashutoshrathi/word-wrap ADDED - 1.2.6
@babel/compat-data DOWNGRADED 7.24.4 7.24.1
@babel/core DOWNGRADED 7.24.4 7.24.3
@babel/generator DOWNGRADED 7.24.4 7.24.1
@babel/helper-create-class-features-plugin DOWNGRADED 7.24.4 7.24.1
@babel/helper-define-polyfill-provider DOWNGRADED 0.6.2 0.6.1
@babel/helpers DOWNGRADED 7.24.4 7.24.1
@babel/parser DOWNGRADED 7.24.4 7.24.1
@babel/plugin-bugfix-firefox-class-in-computed-class-key REMOVED 7.24.4 -
@babel/plugin-proposal-logical-assignment-operators ADDED - 7.20.7
@babel/plugin-transform-block-scoping DOWNGRADED 7.24.4 7.24.1
@babel/plugin-transform-class-static-block DOWNGRADED 7.24.4 7.24.1
@babel/plugin-transform-typescript DOWNGRADED 7.24.4 7.24.1
@babel/preset-env DOWNGRADED 7.24.4 7.24.3
@babel/runtime DOWNGRADED 7.24.4 7.24.1
@firmnav/eslint-github-actions-formatter ADDED - 1.0.1
@humanwhocodes/object-schema DOWNGRADED 2.0.3 2.0.2
@inquirer/figures ADDED - 1.0.1
@isaacs/ttlcache ADDED - 1.4.1
@ljharb/through ADDED - 2.3.13
@octokit/auth-token UPDATED 3.0.4 4.0.0
@octokit/core UPDATED 4.2.4 5.2.0
@octokit/endpoint UPDATED 7.0.6 9.0.5
@octokit/graphql UPDATED 5.0.6 7.1.0
@octokit/openapi-types UPDATED 18.1.1 22.1.0
@octokit/plugin-paginate-rest UPDATED 6.1.2 9.2.1
@octokit/plugin-request-log UPDATED 1.0.4 4.0.1
@octokit/plugin-rest-endpoint-methods UPDATED 7.2.3 10.4.1
@octokit/request UPDATED 6.2.8 8.4.0
@octokit/request-error UPDATED 3.0.3 5.1.0
@octokit/rest UPDATED 19.0.11 20.1.0
@octokit/tsconfig REMOVED 1.0.2 -
@octokit/types UPDATED 10.0.0 13.4.1
@react-native-community/cli UPDATED 10.2.7 14.0.0-alpha.4
@react-native-community/cli-clean UPDATED 10.1.1 14.0.0-alpha.4
@react-native-community/cli-config UPDATED 10.1.1 14.0.0-alpha.4
@react-native-community/cli-debugger-ui UPDATED 10.0.0 14.0.0-alpha.4
@react-native-community/cli-doctor UPDATED 10.2.7 14.0.0-alpha.4
@react-native-community/cli-hermes REMOVED 10.2.7 -
@react-native-community/cli-platform-android UPDATED 10.2.0 14.0.0-alpha.4
@react-native-community/cli-platform-apple ADDED - 14.0.0-alpha.4
@react-native-community/cli-platform-ios UPDATED 10.2.5 14.0.0-alpha.4
@react-native-community/cli-plugin-metro REMOVED 10.2.3 -
@react-native-community/cli-server-api UPDATED 10.1.1 14.0.0-alpha.4
@react-native-community/cli-tools UPDATED 10.1.1 14.0.0-alpha.4
@react-native-community/cli-types UPDATED 10.0.0 14.0.0-alpha.4
@react-native-community/eslint-config REMOVED 3.2.0 -
@react-native-community/eslint-plugin REMOVED 1.3.0 -
@react-native/assets REMOVED 1.0.0 -
@react-native/assets-registry ADDED - 0.74.81
@react-native/babel-plugin-codegen ADDED - 0.74.81
@react-native/babel-preset ADDED - 0.74.81
@react-native/codegen ADDED - 0.74.81
@react-native/community-cli-plugin ADDED - 0.74.81
@react-native/debugger-frontend ADDED - 0.74.81
@react-native/dev-middleware ADDED - 0.74.81
@react-native/eslint-config ADDED - 0.74.81
@react-native/eslint-plugin ADDED - 0.74.81
@react-native/gradle-plugin ADDED - 0.74.81
@react-native/js-polyfills ADDED - 0.74.81
@react-native/metro-babel-transformer ADDED - 0.74.81
@react-native/normalize-color REMOVED 2.1.0 -
@react-native/normalize-colors ADDED - 0.74.81
@react-native/polyfills REMOVED 2.0.0 -
@react-native/virtualized-lists ADDED - 0.74.81
@rnx-kit/chromium-edge-launcher ADDED - 1.0.0
@sindresorhus/merge-streams ADDED - 2.3.0
@testing-library/react-native UPDATED 12.4.5 12.5.0
@tootallnate/quickjs-emscripten ADDED - 0.23.0
@tsconfig/react-native REMOVED 3.0.5 -
@types/minimist ADDED - 1.2.5
@types/node DOWNGRADED 20.12.7 18.19.26
@types/node-forge ADDED - 1.3.11
@types/react-test-renderer REMOVED 18.3.0 -
@types/scheduler ADDED - 0.16.8
@typescript-eslint/eslint-plugin DOWNGRADED 7.7.1 6.21.0
@typescript-eslint/parser DOWNGRADED 7.7.1 6.21.0
@typescript-eslint/scope-manager DOWNGRADED 7.7.1 6.21.0
@typescript-eslint/type-utils DOWNGRADED 7.7.1 6.21.0
@typescript-eslint/types DOWNGRADED 7.7.1 6.21.0
@typescript-eslint/typescript-estree DOWNGRADED 7.7.1 6.21.0
@typescript-eslint/utils DOWNGRADED 7.7.1 6.21.0
@typescript-eslint/visitor-keys DOWNGRADED 7.7.1 6.21.0
absolute-path REMOVED 0.0.0 -
acorn-walk REMOVED 8.3.2 -
agent-base DOWNGRADED 7.1.1 7.1.0
aggregate-error UPDATED 3.1.0 4.0.1
arrify ADDED - 1.0.1
async REMOVED 3.2.5 -
babel-plugin-polyfill-corejs2 DOWNGRADED 0.4.11 0.4.10
babel-plugin-polyfill-regenerator DOWNGRADED 0.6.2 0.6.1
babel-plugin-syntax-trailing-function-commas REMOVED 7.0.0-beta.0 -
babel-preset-fbjs REMOVED 3.4.0 -
big-integer REMOVED 1.6.52 -
bl DOWNGRADED 5.1.0 4.1.0
bplist-parser REMOVED 0.2.0 -
buffer DOWNGRADED 6.0.3 5.7.1
bundle-name UPDATED 3.0.0 4.1.0
camelcase-keys ADDED - 7.0.2
caniuse-lite DOWNGRADED 1.0.30001614 1.0.30001600
chrome-launcher ADDED - 0.15.2
cjs-module-lexer DOWNGRADED 1.3.1 1.2.3
clean-stack UPDATED 2.2.0 4.2.0
core-js-compat DOWNGRADED 3.37.0 3.36.1
cosmiconfig UPDATED 8.1.3 9.0.0
dayjs DOWNGRADED 1.11.11 1.11.10
decamelize UPDATED 1.2.0 5.0.1
decamelize-keys ADDED - 1.1.1
dedent DOWNGRADED 1.5.3 1.5.1
default-browser UPDATED 4.0.0 5.2.1
default-browser-id UPDATED 3.0.0 5.0.0
degenerator UPDATED 4.0.4 5.0.1
del UPDATED 6.1.1 7.1.0
del-cli ADDED - 5.1.0
deprecated-react-native-prop-types REMOVED 3.0.2 -
electron-to-chromium DOWNGRADED 1.4.750 1.4.715
emoji-regex UPDATED 9.2.2 10.3.0
env-paths ADDED - 2.2.1
envinfo DOWNGRADED 7.13.0 7.11.1
es-abstract DOWNGRADED 1.23.3 1.23.2
es-iterator-helpers DOWNGRADED 1.0.19 1.0.18
escodegen UPDATED 1.14.3 2.1.0
eslint-plugin-ft-flow DOWNGRADED 3.0.7 2.0.3
eslint-plugin-jest DOWNGRADED 27.9.0 26.9.0
eslint-plugin-react-hooks DOWNGRADED 4.6.2 4.6.0
execa UPDATED 7.2.0 8.0.1
figures REMOVED 5.0.0 -
flow-enums-runtime ADDED - 0.0.6
flow-parser UPDATED 0.185.2 0.231.0
get-east-asian-width ADDED - 1.2.0
get-stream UPDATED 6.0.1 8.0.1
git-url-parse UPDATED 13.1.0 14.0.0
globby UPDATED 13.1.4 14.0.1
got UPDATED 12.6.1 13.0.0
graceful-fs UPDATED 4.2.10 4.2.11
hard-rejection ADDED - 2.1.0
has-yarn REMOVED 3.0.0 -
hermes-estree UPDATED 0.8.0 0.20.1
hermes-parser UPDATED 0.8.0 0.20.1
hermes-profile-transformer REMOVED 0.0.6 -
human-signals UPDATED 4.3.1 5.0.0
image-size UPDATED 0.6.3 1.1.1
indent-string UPDATED 4.0.0 5.0.0
inquirer UPDATED 9.2.6 9.2.19
ip REMOVED 1.1.9 -
is-in-ci ADDED - 0.1.0
is-path-cwd UPDATED 2.2.0 3.0.0
is-path-inside UPDATED 3.0.3 4.0.0
is-plain-obj ADDED - 1.1.0
is-plain-object DOWNGRADED 5.0.0 2.0.4
is-unicode-supported UPDATED 1.3.0 2.0.0
is-wsl UPDATED 2.2.0 3.1.0
is-yarn-global REMOVED 0.4.1 -
issue-parser UPDATED 6.0.0 7.0.0
jest-serializer REMOVED 27.5.1 -
jetifier REMOVED 2.0.0 -
joi DOWNGRADED 17.13.0 17.12.2
lighthouse-logger ADDED - 1.4.2
log-symbols UPDATED 5.1.0 6.0.0
lru-cache DOWNGRADED 10.2.2 10.2.0
map-obj ADDED - 4.3.0
marky ADDED - 1.2.5
metro UPDATED 0.73.10 0.80.7
metro-babel-transformer UPDATED 0.73.10 0.80.7
metro-cache UPDATED 0.73.10 0.80.7
metro-cache-key UPDATED 0.73.10 0.80.7
metro-config UPDATED 0.73.10 0.80.7
metro-core UPDATED 0.73.10 0.80.7
metro-file-map UPDATED 0.73.10 0.80.7
metro-hermes-compiler REMOVED 0.73.10 -
metro-inspector-proxy REMOVED 0.73.10 -
metro-minify-terser UPDATED 0.73.10 0.80.7
metro-minify-uglify REMOVED 0.73.10 -
metro-react-native-babel-preset REMOVED 0.77.0 -
metro-react-native-babel-transformer REMOVED 0.73.10 -
metro-resolver UPDATED 0.73.10 0.80.7
metro-runtime UPDATED 0.73.10 0.80.7
metro-source-map UPDATED 0.73.10 0.80.7
metro-symbolicate UPDATED 0.73.10 0.80.7
metro-transform-plugins UPDATED 0.73.10 0.80.7
metro-transform-worker UPDATED 0.73.10 0.80.7
minimatch DOWNGRADED 9.0.4 9.0.3
minimist-options ADDED - 4.1.0
mkdirp UPDATED 0.5.6 1.0.4
natural-compare-lite REMOVED 1.4.0 -
nice-try REMOVED 1.0.5 -
node-abort-controller ADDED - 3.1.1
node-fetch UPDATED 3.3.1 3.3.2
node-forge ADDED - 1.3.1
ob1 UPDATED 0.73.10 0.80.7
open UPDATED 9.1.0 10.1.0
optionator DOWNGRADED 0.9.4 0.9.3
ora UPDATED 6.3.1 8.0.1
p-finally REMOVED 1.0.0 -
p-map UPDATED 4.0.0 5.5.0
pac-proxy-agent UPDATED 6.0.4 7.0.1
pac-resolver UPDATED 6.0.2 7.0.1
path-type UPDATED 4.0.0 5.0.0
promise.allsettled UPDATED 1.0.6 1.0.7
proxy-agent UPDATED 6.2.1 6.4.0
querystring ADDED - 0.2.1
queue ADDED - 6.0.2
react-devtools-core UPDATED 4.28.5 5.0.2
react-native UPDATED 0.71.19 0.74.0
react-native-builder-bob UPDATED 0.20.4 0.23.2
react-native-codegen REMOVED 0.71.6 -
react-native-gradle-plugin REMOVED 0.71.19 -
react-refresh UPDATED 0.4.3 0.14.0
redent UPDATED 3.0.0 4.0.0
release-it UPDATED 15.11.0 17.2.1
run-applescript UPDATED 5.0.0 7.0.0
scheduler UPDATED 0.23.2 0.24.0-canary-efb381bbf-20230505
selfsigned ADDED - 2.4.1
signal-exit UPDATED 3.0.7 4.1.0
slash UPDATED 4.0.0 5.1.0
socks DOWNGRADED 2.8.3 2.8.1
socks-proxy-agent DOWNGRADED 8.0.3 8.0.2
source-map DOWNGRADED 0.7.4 0.6.1
stdin-discarder UPDATED 0.1.0 0.2.2
string-width UPDATED 5.1.2 7.1.0
strip-eof REMOVED 1.0.0 -
strip-indent UPDATED 3.0.0 4.0.0
temp-dir ADDED - 2.0.0
terser DOWNGRADED 5.30.4 5.29.2
titleize REMOVED 3.0.0 -
trim-newlines ADDED - 4.1.1
type-fest DOWNGRADED 4.18.0 4.14.0
uglify-es REMOVED 3.3.9 -
undici DOWNGRADED 5.28.4 5.28.3
unicorn-magic ADDED - 0.1.0
untildify REMOVED 4.0.0 -
update-notifier UPDATED 6.0.2 7.0.0
use-sync-external-store REMOVED 1.2.2 -
vm2 REMOVED 3.9.19 -
wildcard-match UPDATED 5.1.2 5.1.3
word-wrap REMOVED 1.2.5 -
yaml UPDATED 1.10.2 2.4.1

@mrousavy

This comment was marked as resolved.

@mrousavy
Copy link
Owner Author

nvm - it runs on iOS! 🎉

now to Android...

@pigeonmal
Copy link

I try beta 2, the build don't work check logs : https://pastebin.com/VUjTDFzV

I fixed that in node_modules files:

  1. node_modules/react-native-mmkv/react-native.config.js
    Modified cxxModuleCMakeListsPath to CMakeLists.txt
  2. Delete build folder in node_modules/react-native-mmkv/android/build/
  3. Rebuild
  4. THE APP AND RN MMKV WORK !!

@mrousavy
Copy link
Owner Author

Yea this seems like a bug in RN Community CLI. The path is wrong when rebuilding.

@mrousavy
Copy link
Owner Author

CI is green! 🎉🟢😍

react-native-mmkv V3 is ready 💪

I am a bit hesitant on merging this to main because it requires the new architecture...

@mrousavy mrousavy merged commit 03d2772 into master Apr 30, 2024
9 checks passed
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.

3 participants