Base Bytecode Optimization
Base bytecode optimization generates your new Hermes bundle using the previously shipped bundle (the "base") as a reference. This was acheived by passing a flag --base-bytecode <path-to-base-bundle> to the Hermes CLI while generating the new bundle. This results in a smaller patch bundle because only the bytecode differences are transmitted (vs. the base).
Size Comparison
File Size Comparison
| Bundle Type | Original | With Deflate | With Brotli |
|---|---|---|---|
| Uncompressed Full Bundle | 24.5 MB | 11.04 MB | 8.14 MB |
| Uncompressed Patch Bundle | ~24.5 MB | 3.82 MB | 2.9 MB |
| Uncompressed Patch Bundle With Base Bytecode | ~24.5 MB | 1.1 MB | 0.8 MB (96% smaller🔥) |
Available starting from SDK v1.2.0.
Enable Base Bytecode Optimization
To use this feature, set the path to the old bundle saved in the Patch Update Guide - Step 1. You’ll use this as the base when generating the new bundle in Step 3 of the Patch Update Guide.
- Android
- iOS
Either set the environment variable or use the gradle.properties file.
# Environment variable
export DOTA_BASE_BUNDLE_PATH=.dota-versions/v1.0.0-android/index.android.bundle && ./gradlew assembleRelease
# gradle.properties
dotaBaseBundlePath=.dota-versions/v1.0.0-android/index.android.bundle
React Native does not directly expose --base-bytecode flag for iOS, so we add support via a patch to react-native-xcode.sh using patch-package.
- Install patch-package (skip if already installed):
yarn add patch-package postinstall-postinstall --dev
Add to package.json:
{
"scripts": {
"postinstall": "patch-package"
}
}
- Modify
node_modules/react-native/scripts/react-native-xcode.shto pass the base bytecode flag to Hermes. Insert before the Hermes CLI execution block:
# Inside react-native-xcode.sh
BASE_BYTECODE_PATH=""
if [[ ! -z $DOTA_BASE_BUNDLE_PATH ]]; then
if [[ -f $DOTA_BASE_BUNDLE_PATH ]]; then
BASE_BYTECODE_PATH="--base-bytecode $DOTA_BASE_BUNDLE_PATH"
echo "Using --base-bytecode with path: $DOTA_BASE_BUNDLE_PATH"
else
echo "Not using --base-bytecode, path: $DOTA_BASE_BUNDLE_PATH, file not found"
BASE_BYTECODE_PATH=""
fi
fi
"$HERMES_CLI_PATH" -emit-binary -max-diagnostic-width=80 $EXTRA_COMPILER_ARGS -out "$DEST/$BUNDLE_NAME.jsbundle" "$BUNDLE_FILE" $BASE_BYTECODE_PATH
Create the patch:
yarn patch-package react-native
- Provide the base bundle path via env var (use the old bundle path saved in
.dota-versions/):
# .xcode.env
export DOTA_BASE_BUNDLE_PATH=.dota-versions/v1.0.0-ios/main.jsbundle
# Inline when building
export DOTA_BASE_BUNDLE_PATH=.dota-versions/v1.0.0-ios/main.jsbundle && yarn ios --mode=Release
Follow every step in the Patch Update Guide; this feature only adds one extra action just before generating the new bundle (set the base bundle path).
If you are using manual bundle generation as described in Bundle Generation Guide, pass --base-bundle-path <path-to-old-bundle> to the CLI.
Disable Base Bytecode Optimization
To disable this feature, unset the DOTA_BASE_BUNDLE_PATH environment variable.
Verify Base Bytecode Optimization
To verify that the base bytecode optimization is enabled, you can check the size of the patch bundle being downloaded. Use sync API to verify the size of the patch bundle being downloaded.
codePush.sync(
{},
(status) => {
console.log(status);
},
({ receivedBytes, totalBytes }) => {
console.log(`Downloaded ${receivedBytes} of ${totalBytes} bytes`);
}
);
✅ Setup complete. Your next bundle builds will use the saved base to produce smaller patch bundles. Continue with create‑patch and release steps in the Patch Update Guide.