~/swaraj.dev
Back to all posts
March 16, 20261 min read

Speed Up RN Startup with Metro's Inline Requires

Learn how Metro's inlineRequires feature can defer module evaluation, shrinking JavaScript bundle size and improving cold start performance in React Native apps.

react nativeperformancemetro bundler

Insight

Metro bundles every imported module eagerly, which means the JavaScript engine parses and executes code you might never use on the first screen. Enabling inlineRequires tells Metro to wrap each require call in a lazy getter, loading the module only when it’s actually accessed. This reduces the initial bundle size and can shave 100‑200 ms off cold start times, especially on low‑end Android devices.

Example

// metro.config.js
const { getDefaultConfig } = require('expo/metro-config');

module.exports = (async () => {
  const defaultConfig = await getDefaultConfig(__dirname);
  return {
    ...defaultConfig,
    transformer: {
      ...defaultConfig.transformer,
      // Enable lazy loading of modules
      inlineRequires: true,
    },
  };
})();

Takeaway

Flip the inlineRequires flag in your Metro config for a quick, zero‑code‑change performance win. Remember to profile after the change—some apps with heavy initialization logic may need fine‑tuning, but most will see a noticeable startup boost.