expo-modules-core 58.0.17 → 58.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/ExpoModulesCore.podspec +10 -1
  3. package/android/build.gradle +3 -3
  4. package/android/prebuilt/metadata.json +2 -2
  5. package/android/prebuilt/native-libs.tar.xz +0 -0
  6. package/android/src/main/java/expo/modules/v2/ExpoModulesV2Host.kt +4 -0
  7. package/build/ts-declarations/global.d.ts +0 -1
  8. package/common/cpp/EventEmitter.cpp +8 -4
  9. package/expo-module-gradle-plugin/build.gradle.kts +1 -1
  10. package/ios/Api/Factories/ClassFactories.swift +1 -1
  11. package/ios/Benchmarks/Benchmarks.swift +15 -0
  12. package/ios/Benchmarks/EventEmitterBenchmarks.swift +140 -0
  13. package/ios/Benchmarks/FunctionBenchmarks.swift +112 -0
  14. package/ios/Benchmarks/SharedObjectBenchmarks.swift +80 -0
  15. package/ios/Core/AppContext.swift +22 -2
  16. package/ios/Core/ArrayBuffers/ArrayBuffer.swift +8 -3
  17. package/ios/Core/Classes/ClassDefinition.swift +15 -5
  18. package/ios/Core/EventListener.swift +4 -0
  19. package/ios/Core/Events/EventEmitter.swift +56 -12
  20. package/ios/Core/Events/EventObservingDefinition.swift +4 -0
  21. package/ios/Core/Functions/AsyncFunctionDefinition.swift +4 -0
  22. package/ios/Core/Functions/ConcurrentFunctionDefinition.swift +4 -0
  23. package/ios/Core/Functions/OptimizedAsyncFunctionDefinition.swift +4 -0
  24. package/ios/Core/Functions/OptimizedSyncFunctionDefinition.swift +4 -0
  25. package/ios/Core/Functions/StaticFunctionDefinition.swift +12 -16
  26. package/ios/Core/Functions/SyncFunctionDefinition.swift +4 -0
  27. package/ios/Core/ModuleHolder.swift +1 -0
  28. package/ios/Core/ModuleRegistry.swift +2 -2
  29. package/ios/Core/Modules/Module.swift +7 -5
  30. package/ios/Core/Modules/ModuleDefinition.swift +43 -16
  31. package/ios/Core/Objects/ConstantDefinition.swift +4 -0
  32. package/ios/Core/Objects/ObjectDefinition.swift +35 -31
  33. package/ios/Core/Objects/PropertyDefinition.swift +4 -0
  34. package/ios/Core/Protocols/AnyDefinition.swift +43 -1
  35. package/ios/Core/Protocols/AnyModule.swift +1 -1
  36. package/ios/Core/TypeName.swift +12 -0
  37. package/ios/Core/TypedArrays/ConcreteTypedArrays.swift +58 -46
  38. package/ios/Core/TypedArrays/TypedArray.swift +11 -5
  39. package/ios/Core/Views/ConcreteViewProp.swift +4 -0
  40. package/ios/Core/Views/SwiftUI/SwiftUIViewDefinition.swift +1 -1
  41. package/ios/Core/Views/ViewDefinition.swift +36 -15
  42. package/ios/Core/Views/ViewLifecycleMethod.swift +4 -0
  43. package/ios/JS/EXJSUtils.h +16 -0
  44. package/ios/JS/EXJSUtils.mm +13 -4
  45. package/ios/Utilities/Utilities.swift +0 -14
  46. package/package.json +4 -4
  47. package/prebuilds/output/debug/xcframeworks/ExpoModulesCore.tar.gz +0 -0
  48. package/prebuilds/output/debug/xcframeworks/ExpoModulesWorklets.tar.gz +0 -0
  49. package/prebuilds/output/headers/xcframeworks/ExpoModulesCoreHeaders.tar.gz +0 -0
  50. package/prebuilds/output/release/xcframeworks/ExpoModulesCore.tar.gz +0 -0
  51. package/prebuilds/output/release/xcframeworks/ExpoModulesWorklets.tar.gz +0 -0
  52. package/spm.config.json +9 -1
  53. package/src/ts-declarations/global.ts +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 58.0.19
4
+
5
+ ### Patch Changes
6
+
7
+ - [iOS] Speed up module registration at app launch by classifying definition elements without protocol conformance lookups. ([#51456](https://github.com/expo/expo/pull/51456) by [@Kudo](https://github.com/Kudo))
8
+ - [iOS] Reduced the overhead of emitting events without a payload. ([#51560](https://github.com/expo/expo/pull/51560) by [@tsapeta](https://github.com/tsapeta))
9
+ - [iOS] Speed up app launch by computing default module, class and view names without protocol conformance lookups. ([#51455](https://github.com/expo/expo/pull/51455) by [@Kudo](https://github.com/Kudo))
10
+ - [iOS] Publish a headers XCFramework for `ExpoModulesCore` with the package, at `prebuilds/output/headers/xcframeworks/ExpoModulesCoreHeaders.tar.gz`. ([#51243](https://github.com/expo/expo/pull/51243) by [@chrfalch](https://github.com/chrfalch))
11
+ - [iOS] Add `isFunction()`, `isTypedArray()`, `isArrayBuffer()`, `getTypedArray(in:)`, `getArrayBuffer(in:)`, `getBigInt(in:)` and `kind` to `JavaScriptUnownedValue`. `Data`, typed arrays, `ArrayBuffer` and integers from a `BigInt` now decode function arguments without copying them into an owning `JavaScriptValue`: a `Data` argument is about 10% faster to decode, and an `Int64` from a `BigInt` about 8× faster. ([#51558](https://github.com/expo/expo/pull/51558) by [@tsapeta](https://github.com/tsapeta))
12
+ - [Internal] Drop unused `EXPO_PROJECT_ROOT` and `EXPO_ROUTER_ABS_APP_ROOT` variables and corresponding invalidation. ([#51540](https://github.com/expo/expo/pull/51540) by [@kitten](https://github.com/kitten))
13
+ - Updated dependencies. ([#51243](https://github.com/expo/expo/pull/51243), [#51562](https://github.com/expo/expo/pull/51562), [#51565](https://github.com/expo/expo/pull/51565), [#51564](https://github.com/expo/expo/pull/51564), [#51560](https://github.com/expo/expo/pull/51560), [#51558](https://github.com/expo/expo/pull/51558))
14
+ - expo-modules-jsi@58.0.14
15
+
16
+ ## 58.0.18
17
+
18
+ ### Patch Changes
19
+
20
+ - [iOS] Fix slow cold launches in brownfield apps where the `ExpoModulesProvider` lookup scanned `Bundle.allFrameworks` inside `+load`. The lookup now tries the framework that contains ExpoModulesCore before falling back to the scan. ([#51481](https://github.com/expo/expo/pull/51481) by [@expo-bot](https://github.com/expo-bot))
21
+ - [iOS] Update `expo-modules-macros` to 0.20.0, which binds `@JS` functions and setters that return nothing through the `Void` overload, so they no longer build an `undefined` value on each call. ([#51548](https://github.com/expo/expo/pull/51548) by [@tsapeta](https://github.com/tsapeta))
22
+ - [iOS] Reduced the overhead of emitting module events. ([#51553](https://github.com/expo/expo/pull/51553) by [@tsapeta](https://github.com/tsapeta))
23
+ - Updated dependencies. ([#51496](https://github.com/expo/expo/pull/51496), [#51499](https://github.com/expo/expo/pull/51499), [#51498](https://github.com/expo/expo/pull/51498), [#51371](https://github.com/expo/expo/pull/51371))
24
+ - expo-modules-jsi@58.0.13
25
+
3
26
  ## 58.0.17
4
27
 
5
28
  ### Patch Changes
@@ -119,7 +119,7 @@ Pod::Spec.new do |s|
119
119
  s.static_framework = true
120
120
  s.header_dir = 'ExpoModulesCore'
121
121
  s.source_files = 'ios/**/*.{h,m,mm,swift,cpp}', 'common/cpp/**/*.{h,cpp}'
122
- s.exclude_files = ['ios/Tests', 'ios/Worklets', 'ios/WorkletsTests', 'ios/WorkletsAdapter']
122
+ s.exclude_files = ['ios/Tests', 'ios/Benchmarks', 'ios/Worklets', 'ios/WorkletsTests', 'ios/WorkletsAdapter']
123
123
  s.compiler_flags = compiler_flags
124
124
  s.private_header_files = ['ios/**/*+Private.h', 'ios/**/Swift.h']
125
125
  end
@@ -145,4 +145,13 @@ Pod::Spec.new do |s|
145
145
  'SWIFT_OBJC_BRIDGING_HEADER' => '$(PODS_TARGET_SRCROOT)/ios/Tests/Tests-Bridging-Header.h'
146
146
  }
147
147
  end
148
+
149
+ # Performance benchmarks. A separate spec, so unit test runs neither build nor run them.
150
+ s.test_spec 'Benchmarks' do |test_spec|
151
+ test_spec.dependency 'ExpoModulesTestCore'
152
+ test_spec.source_files = 'ios/Benchmarks/**/*.swift'
153
+ test_spec.pod_target_xcconfig = {
154
+ 'OTHER_LDFLAGS' => '$(inherited) -lc++'
155
+ }
156
+ end
148
157
  end
@@ -46,7 +46,7 @@ if (shouldIncludeCompose) {
46
46
  }
47
47
 
48
48
  group = 'host.exp.exponent'
49
- version = '58.0.17'
49
+ version = '58.0.19'
50
50
 
51
51
  def isExpoModulesCoreTests = {
52
52
  Gradle gradle = getGradle()
@@ -97,7 +97,7 @@ if (workletsProject != null) {
97
97
 
98
98
  def reactNativeWorkletsRootDir = workletsProject?.projectDir?.parentFile
99
99
 
100
- def expoModulesV2Version = "0.2.4"
100
+ def expoModulesV2Version = "0.2.5"
101
101
 
102
102
  configurations {
103
103
  // Artifact-only: the C++ sources, not something to put on any classpath.
@@ -175,7 +175,7 @@ android {
175
175
  defaultConfig {
176
176
  consumerProguardFiles 'proguard-rules.pro'
177
177
  versionCode 1
178
- versionName "58.0.17"
178
+ versionName "58.0.19"
179
179
  buildConfigField "String", "EXPO_MODULES_CORE_VERSION", "\"${versionName}\""
180
180
  buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true"
181
181
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "reactNativeVersion": "0.88.0",
3
- "sourceHash": "4a484f59a9d342285a14ab862c0ea08a",
3
+ "sourceHash": "0b72456880c81b38b6a81f2e69eb4cf4",
4
4
  "variants": [
5
5
  "debug",
6
6
  "release"
@@ -16,5 +16,5 @@
16
16
  "libexpo-modules-jsi.so"
17
17
  ],
18
18
  "stripped": true,
19
- "createdAt": "2026-10-13T15:42:19.061709444Z"
19
+ "createdAt": "2026-10-15T17:55:40.061872925Z"
20
20
  }
Binary file
@@ -3,6 +3,7 @@ package expo.modules.v2
3
3
  import com.facebook.react.bridge.ReactApplicationContext
4
4
  import expo.modules.kotlin.logger
5
5
  import io.github.expo.modules.v2.Module
6
+ import io.github.expo.modules.v2.react.ExpoModulesV2React
6
7
  import io.github.expo.modules.v2.react.ReactRuntime
7
8
  import java.lang.reflect.Modifier
8
9
 
@@ -30,6 +31,9 @@ object ExpoModulesV2Host {
30
31
  }
31
32
 
32
33
  try {
34
+ // Must run before `ReactRuntime` initializes. Its superclass, kolibri's `NativeObject`,
35
+ // otherwise loads the native library under kolibri's default name, which does not exist.
36
+ ExpoModulesV2React.ensureLoaded()
33
37
  // The runtime creates a context of its own, and serves the modules of that context.
34
38
  val attached = ReactRuntime.attach(reactContext)
35
39
  try {
@@ -13,7 +13,6 @@ export interface ExpoProcessEnv {
13
13
  /** Used in `@expo/metro-runtime`. */
14
14
  EXPO_DEV_SERVER_ORIGIN?: string;
15
15
  EXPO_ROUTER_IMPORT_MODE?: string;
16
- EXPO_ROUTER_ABS_APP_ROOT?: string;
17
16
  EXPO_ROUTER_APP_ROOT?: string;
18
17
  /** Maps to the `experiments.baseUrl` property in the project Expo config. This is injected by `babel-preset-expo` and supports automatic cache invalidation. */
19
18
  EXPO_BASE_URL?: string;
@@ -41,10 +41,11 @@ size_t Listeners::listenersCount(const std::string& eventName) noexcept {
41
41
  }
42
42
 
43
43
  void Listeners::call(jsi::Runtime &runtime, const std::string& eventName, const jsi::Object &thisObject, const jsi::Value *args, size_t count) noexcept {
44
- if (!listenersMap.contains(eventName)) {
44
+ auto entry = listenersMap.find(eventName);
45
+ if (entry == listenersMap.end()) {
45
46
  return;
46
47
  }
47
- ListenersList &listenersList = listenersMap[eventName];
48
+ ListenersList &listenersList = entry->second;
48
49
  size_t listSize = listenersList.size();
49
50
 
50
51
  if (listSize == 0) {
@@ -102,8 +103,11 @@ NativeState::~NativeState() {
102
103
  }
103
104
 
104
105
  NativeState::Shared NativeState::get(jsi::Runtime &runtime, const jsi::Object &object, bool createIfMissing) {
105
- if (object.hasNativeState<NativeState>(runtime)) {
106
- return object.getNativeState<NativeState>(runtime);
106
+ // The untyped `hasNativeState` is a single runtime call. The state is then fetched once, and its type is checked.
107
+ if (object.hasNativeState(runtime)) {
108
+ if (NativeState::Shared state = std::dynamic_pointer_cast<NativeState>(object.getNativeState(runtime))) {
109
+ return state;
110
+ }
107
111
  }
108
112
  if (createIfMissing) {
109
113
  NativeState::Shared state = std::make_shared<NativeState>();
@@ -33,7 +33,7 @@ dependencies {
33
33
  implementation("com.facebook.react:react-native-gradle-plugin")
34
34
  implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
35
35
  implementation("io.github.expo.pika:pika-gradle:1.1.0")
36
- implementation("io.github.expo:expo-modules-v2-gradle-plugin:0.2.4")
36
+ implementation("io.github.expo:expo-modules-v2-gradle-plugin:0.2.5")
37
37
 
38
38
  if (isExpoAutolinkingSettingsPluginAvailable) {
39
39
  implementation("expo.modules:expo-autolinking-plugin-shared")
@@ -49,5 +49,5 @@ public func Class<SharedObjectType: SharedObject>(
49
49
  _ sharedObjectType: SharedObjectType.Type,
50
50
  @ClassDefinitionBuilder<SharedObjectType> @_implicitSelfCapture _ elements: () -> [AnyClassDefinitionElement]
51
51
  ) -> ClassDefinition {
52
- return ClassDefinition(name: String(describing: SharedObjectType.self), associatedType: SharedObjectType.self, elements: elements())
52
+ return ClassDefinition(name: unqualifiedTypeName(SharedObjectType.self), associatedType: SharedObjectType.self, elements: elements())
53
53
  }
@@ -0,0 +1,15 @@
1
+ // Copyright 2026-present 650 Industries. All rights reserved.
2
+
3
+ import Testing
4
+
5
+ /// Umbrella suite for the ExpoModulesCore benchmarks; the other files in this directory extend it.
6
+ ///
7
+ /// The benchmarks are the `Benchmarks` test spec of the pod, separate from the unit tests. Build them in
8
+ /// the Release configuration, so the numbers reflect optimized code. Each case prints one `[benchmark]`
9
+ /// line with the median and minimum ns/op.
10
+ ///
11
+ /// The suite is serialized so only one benchmark runs at a time: the `JavaScriptActor` executor runs
12
+ /// jobs synchronously on the calling thread, so cases running in parallel would disturb each other's
13
+ /// measurements.
14
+ @Suite(.serialized)
15
+ struct Benchmarks {}
@@ -0,0 +1,140 @@
1
+ // Copyright 2026-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesTestCore
4
+ import Testing
5
+
6
+ @testable import ExpoModulesCore
7
+
8
+ /// Benchmarks for emitting module events to JavaScript. Each case emits from Swift in a loop to a
9
+ /// no-op JS listener. The standalone test runtime runs scheduled work synchronously, so every operation
10
+ /// covers the whole path: scheduling, converting the payload, reaching the module's JavaScript object
11
+ /// and calling the listener. Read the payload cases against `emit: no payload`.
12
+ extension Benchmarks {
13
+ @Test
14
+ func `emit: no payload`() async throws {
15
+ try await eventBenchmarkCase { module, runtime in
16
+ try benchmark("emit: no payload", runtime: runtime) { iterations in
17
+ for _ in 0..<iterations {
18
+ module.emit(event: "ping")
19
+ }
20
+ }
21
+ }
22
+ }
23
+
24
+ @Test
25
+ func `emit: no payload, 100 other modules registered`() async throws {
26
+ try await eventBenchmarkCase(otherModuleCount: 100) { module, runtime in
27
+ try benchmark("emit: no payload, 100 other modules registered", runtime: runtime) { iterations in
28
+ for _ in 0..<iterations {
29
+ module.emit(event: "ping")
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ @Test
36
+ func `emit: Int payload`() async throws {
37
+ try await eventBenchmarkCase { module, runtime in
38
+ try benchmark("emit: Int payload", runtime: runtime) { iterations in
39
+ for index in 0..<iterations {
40
+ module.emit(event: "count", payload: index)
41
+ }
42
+ }
43
+ }
44
+ }
45
+
46
+ @Test
47
+ func `emit: Int payload through @Event`() async throws {
48
+ try await eventBenchmarkCase { module, runtime in
49
+ try benchmark("emit: Int payload through @Event", runtime: runtime) { iterations in
50
+ for index in 0..<iterations {
51
+ module.onCount(index)
52
+ }
53
+ }
54
+ }
55
+ }
56
+
57
+ @Test
58
+ func `emit: Int payload as AnyArgument`() async throws {
59
+ try await eventBenchmarkCase { module, runtime in
60
+ try benchmark("emit: Int payload as AnyArgument", runtime: runtime) { iterations in
61
+ for index in 0..<iterations {
62
+ emitAsAnyArgument(module, event: "count", payload: index)
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ @Test
69
+ func `emit: record payload`() async throws {
70
+ try await eventBenchmarkCase { module, runtime in
71
+ try benchmark("emit: record payload", runtime: runtime) { iterations in
72
+ for index in 0..<iterations {
73
+ module.emit(event: "progress", payload: ProgressPayload(percent: index, label: "loading"))
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ @Test
80
+ func `emit: record payload as AnyArgument`() async throws {
81
+ try await eventBenchmarkCase { module, runtime in
82
+ try benchmark("emit: record payload as AnyArgument", runtime: runtime) { iterations in
83
+ for index in 0..<iterations {
84
+ emitAsAnyArgument(module, event: "progress", payload: ProgressPayload(percent: index, label: "loading"))
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+
91
+ @Record
92
+ private struct ProgressPayload {
93
+ var percent: Int = 0
94
+ var label: String = ""
95
+ }
96
+
97
+ @ExpoModule
98
+ private final class EventBenchmarkModule: Module {
99
+ @Event
100
+ var onPing: () -> Void
101
+
102
+ @Event
103
+ var onCount: (Int) -> Void
104
+
105
+ @Event
106
+ var onProgress: (ProgressPayload) -> Void
107
+ }
108
+
109
+ @ExpoModule
110
+ private final class IdleModule: Module {}
111
+
112
+ /// Runs one case with a fresh app context that has `EventBenchmarkModule` registered, with a no-op
113
+ /// JavaScript listener on each of its events. `otherModuleCount` more modules are registered first.
114
+ private func eventBenchmarkCase(
115
+ otherModuleCount: Int = 0,
116
+ _ body: @escaping @JavaScriptActor (EventBenchmarkModule, JavaScriptRuntime) throws -> Void
117
+ ) async throws {
118
+ try await moduleBenchmarkCase { appContext in
119
+ for index in 0..<otherModuleCount {
120
+ appContext.moduleRegistry.register(module: IdleModule(appContext: appContext), name: "IdleModule\(index)")
121
+ }
122
+ return EventBenchmarkModule(appContext: appContext)
123
+ } _: { module, runtime in
124
+ try runtime.eval(
125
+ """
126
+ const listener = () => {};
127
+ expo.modules.EventBenchmarkModule.addListener('ping', listener);
128
+ expo.modules.EventBenchmarkModule.addListener('count', listener);
129
+ expo.modules.EventBenchmarkModule.addListener('progress', listener);
130
+ """
131
+ )
132
+ try body(module, runtime)
133
+ }
134
+ }
135
+
136
+ /// Emits through the `AnyArgument` overload, which a direct call doesn't reach for a payload that is
137
+ /// also `JavaScriptEncodable`.
138
+ private func emitAsAnyArgument<P: AnyArgument>(_ module: EventBenchmarkModule, event: String, payload: sending P) {
139
+ module.emit(event: event, payload: payload)
140
+ }
@@ -0,0 +1,112 @@
1
+ // Copyright 2026-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesTestCore
4
+ import Testing
5
+
6
+ @testable import ExpoModulesCore
7
+
8
+ /// Benchmarks for JavaScript calling `@JS` functions of an `@ExpoModule`. A JavaScript driver runs the
9
+ /// measured loop, so each operation covers the full call: the engine's call dispatch, decoding the
10
+ /// arguments, the Swift function and encoding the result. Read every result against
11
+ /// `JS: empty driver loop`.
12
+ extension Benchmarks {
13
+ @Test
14
+ func `JS: empty driver loop`() async throws {
15
+ try await functionBenchmarkCase(body: "") { run, runtime in
16
+ try benchmark("JS: empty driver loop", runtime: runtime) { iterations in
17
+ _ = try run.call(arguments: iterations)
18
+ }
19
+ }
20
+ }
21
+
22
+ @Test
23
+ func `@JS: no arguments`() async throws {
24
+ try await functionBenchmarkCase(body: "m.noop();") { run, runtime in
25
+ try benchmark("@JS: no arguments", runtime: runtime) { iterations in
26
+ _ = try run.call(arguments: iterations)
27
+ }
28
+ }
29
+ }
30
+
31
+ @Test
32
+ func `@JS: two Double arguments and a Double result`() async throws {
33
+ try await functionBenchmarkCase(body: "m.add(i, 2);") { run, runtime in
34
+ try benchmark("@JS: two Double arguments and a Double result", runtime: runtime) { iterations in
35
+ _ = try run.call(arguments: iterations)
36
+ }
37
+ }
38
+ }
39
+
40
+ @Test
41
+ func `@JS: String argument and result`() async throws {
42
+ try await functionBenchmarkCase(body: "m.echo('hello');") { run, runtime in
43
+ try benchmark("@JS: String argument and result", runtime: runtime) { iterations in
44
+ _ = try run.call(arguments: iterations)
45
+ }
46
+ }
47
+ }
48
+
49
+ @Test
50
+ func `@JS: record argument and result`() async throws {
51
+ try await functionBenchmarkCase(setup: "var point = { x: 1, y: 2 };", body: "m.mirror(point);") { run, runtime in
52
+ try benchmark("@JS: record argument and result", runtime: runtime) { iterations in
53
+ _ = try run.call(arguments: iterations)
54
+ }
55
+ }
56
+ }
57
+
58
+ @Test
59
+ func `@JS: async function with no arguments`() async throws {
60
+ try await functionBenchmarkCase(body: "m.noopAsync();") { run, runtime in
61
+ try benchmark("@JS: async function with no arguments", runtime: runtime) { iterations in
62
+ _ = try run.call(arguments: iterations)
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ @Record
69
+ private struct BenchmarkPoint {
70
+ var x: Double = 0
71
+ var y: Double = 0
72
+ }
73
+
74
+ @ExpoModule
75
+ private final class FunctionBenchmarkModule: Module {
76
+ @JS
77
+ func noop() {}
78
+
79
+ @JS
80
+ func add(a: Double, b: Double) -> Double {
81
+ return a + b
82
+ }
83
+
84
+ @JS
85
+ func echo(text: String) -> String {
86
+ return text
87
+ }
88
+
89
+ @JS
90
+ func mirror(point: BenchmarkPoint) -> BenchmarkPoint {
91
+ return BenchmarkPoint(x: point.y, y: point.x)
92
+ }
93
+
94
+ @JS
95
+ @JavaScriptActor
96
+ func noopAsync() async {}
97
+ }
98
+
99
+ /// Runs one case with `FunctionBenchmarkModule` registered and a JavaScript driver that runs `body` in a
100
+ /// loop, with the module in `m`.
101
+ private func functionBenchmarkCase(
102
+ setup: String = "",
103
+ body: String,
104
+ _ measure: @escaping @JavaScriptActor (borrowing JavaScriptFunction, JavaScriptRuntime) throws -> Void
105
+ ) async throws {
106
+ try await moduleBenchmarkCase { appContext in
107
+ return FunctionBenchmarkModule(appContext: appContext)
108
+ } _: { _, runtime in
109
+ let run = try javaScriptDriver(runtime, setup: "var m = expo.modules.FunctionBenchmarkModule; \(setup)", body: body)
110
+ try measure(run, runtime)
111
+ }
112
+ }
@@ -0,0 +1,80 @@
1
+ // Copyright 2026-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesTestCore
4
+ import Testing
5
+
6
+ @testable import ExpoModulesCore
7
+
8
+ /// Benchmarks for JavaScript using a `@SharedObject` class: creating instances and calling their `@JS`
9
+ /// members. A JavaScript driver runs the measured loop. Read every result against
10
+ /// `JS: empty driver loop`.
11
+ extension Benchmarks {
12
+ @Test
13
+ func `@SharedObject: new instance`() async throws {
14
+ try await sharedObjectBenchmarkCase(body: "new Counter(i);") { run, runtime in
15
+ try benchmark("@SharedObject: new instance", runtime: runtime) { iterations in
16
+ _ = try run.call(arguments: iterations)
17
+ }
18
+ }
19
+ }
20
+
21
+ @Test
22
+ func `@SharedObject: method call`() async throws {
23
+ try await sharedObjectBenchmarkCase(body: "counter.increment(1);") { run, runtime in
24
+ try benchmark("@SharedObject: method call", runtime: runtime) { iterations in
25
+ _ = try run.call(arguments: iterations)
26
+ }
27
+ }
28
+ }
29
+
30
+ @Test
31
+ func `@SharedObject: property read`() async throws {
32
+ try await sharedObjectBenchmarkCase(body: "counter.current;") { run, runtime in
33
+ try benchmark("@SharedObject: property read", runtime: runtime) { iterations in
34
+ _ = try run.call(arguments: iterations)
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ @SharedObject
41
+ private final class BenchmarkCounter: SharedObject {
42
+ private var value: Int
43
+
44
+ @JS
45
+ init(value: Int) {
46
+ self.value = value
47
+ }
48
+
49
+ @JS
50
+ func increment(by amount: Int) -> Int {
51
+ value += amount
52
+ return value
53
+ }
54
+
55
+ @JS
56
+ var current: Int {
57
+ return value
58
+ }
59
+ }
60
+
61
+ @ExpoModule(classes: [BenchmarkCounter.self])
62
+ private final class SharedObjectBenchmarkModule: Module {}
63
+
64
+ /// Runs one case with `SharedObjectBenchmarkModule` registered and a JavaScript driver that runs `body`
65
+ /// in a loop, with the class in `Counter` and one instance in `counter`.
66
+ private func sharedObjectBenchmarkCase(
67
+ body: String,
68
+ _ measure: @escaping @JavaScriptActor (borrowing JavaScriptFunction, JavaScriptRuntime) throws -> Void
69
+ ) async throws {
70
+ try await moduleBenchmarkCase { appContext in
71
+ return SharedObjectBenchmarkModule(appContext: appContext)
72
+ } _: { _, runtime in
73
+ let run = try javaScriptDriver(
74
+ runtime,
75
+ setup: "var Counter = expo.modules.SharedObjectBenchmarkModule.BenchmarkCounter; var counter = new Counter(0);",
76
+ body: body
77
+ )
78
+ try measure(run, runtime)
79
+ }
80
+ }
@@ -764,7 +764,27 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
764
764
  return providerClass.init()
765
765
  }
766
766
 
767
- // [2] Fallback to search for `ExpoModulesProvider` in frameworks (brownfield use case)
767
+ // [2] Fallback to the framework that contains ExpoModulesCore itself (brownfield use case).
768
+ // Brownfield apps often prelink React Native and Expo into one dynamic framework; the
769
+ // generated provider is then compiled into that framework, so its Swift module is the
770
+ // framework's name and the main-bundle lookups above miss. Trying this bundle first avoids
771
+ // the `Bundle.allFrameworks` scan below, which materializes a bundle for every loaded
772
+ // framework and runs inside `+load` on every cold launch.
773
+ let coreBundle = Bundle(for: AppContext.self)
774
+ if coreBundle.bundlePath != Bundle.main.bundlePath {
775
+ let coreBundleNames = [
776
+ coreBundle.infoDictionary?["CFBundleExecutable"],
777
+ coreBundle.infoDictionary?["CFBundleName"]
778
+ ].compactMap { $0 as? String }
779
+
780
+ for providerClassName in moduleProviderClassNames(withName: providerName, bundleNames: coreBundleNames) {
781
+ if let providerClass = NSClassFromString(providerClassName) as? ModulesProvider.Type {
782
+ return providerClass.init()
783
+ }
784
+ }
785
+ }
786
+
787
+ // [3] Fallback to search for `ExpoModulesProvider` in frameworks (brownfield use case)
768
788
  for bundle in Bundle.allFrameworks {
769
789
  let frameworkBundleNames = [
770
790
  bundle.infoDictionary?["CFBundleExecutable"],
@@ -778,7 +798,7 @@ public class AppContext: NSObject, EXAppContextProtocol, @unchecked Sendable {
778
798
  }
779
799
  }
780
800
 
781
- // [3] Fallback to an empty `ModulesProvider` if `ExpoModulesProvider` was not generated
801
+ // [4] Fallback to an empty `ModulesProvider` if `ExpoModulesProvider` was not generated
782
802
  return ModulesProvider()
783
803
  }
784
804
 
@@ -173,10 +173,15 @@ public final class ArrayBuffer: AnyArrayBuffer, Sendable {
173
173
  unownedValue: borrowing JavaScriptUnownedValue,
174
174
  in runtime: borrowing JavaScriptRuntime
175
175
  ) throws -> ArrayBuffer {
176
- guard unownedValue.isObject() else {
177
- throw ArrayBufferJavaScriptValueConversionException(unownedValue.copied(in: runtime).kind)
176
+ // The kind checks read the borrowed value, so neither an `ArrayBuffer` nor a typed array is
177
+ // copied into an owning `JavaScriptValue` first.
178
+ if unownedValue.isArrayBuffer() {
179
+ return ArrayBuffer.from(jsArrayBuffer: unownedValue.getArrayBuffer(in: runtime))
178
180
  }
179
- return try ArrayBuffer.from(jsObject: unownedValue.getObject(in: runtime))
181
+ if unownedValue.isTypedArray() {
182
+ return try ArrayBuffer.from(typedArray: unownedValue.getTypedArray(in: runtime))
183
+ }
184
+ throw ArrayBufferJavaScriptValueConversionException(unownedValue.isObject() ? .object : unownedValue.kind)
180
185
  }
181
186
 
182
187
  @JavaScriptActor
@@ -6,6 +6,10 @@ import ExpoModulesJSI
6
6
  Represents a JavaScript class.
7
7
  */
8
8
  public final class ClassDefinition: ObjectDefinition {
9
+ public override var _definitionClassification: DefinitionClassification {
10
+ return DefinitionClassification(kind: .klass(self))
11
+ }
12
+
9
13
  /**
10
14
  Name of the class.
11
15
  */
@@ -28,13 +32,13 @@ public final class ClassDefinition: ObjectDefinition {
28
32
 
29
33
  private init(_ name: String, associatedType: AnyDynamicType, isSharedRef: Bool, elements: [AnyClassDefinitionElement] = []) {
30
34
  self.name = name
31
- self.constructor = elements.first(where: isConstructor) as? AnySyncFunctionDefinition
32
35
  self.associatedType = associatedType
33
36
  self.isSharedRef = isSharedRef
34
37
 
35
38
  // Constructors can't be passed down to the object definition
36
39
  // as we shouldn't override the default `<Class>.prototype.constructor`.
37
- let elementsWithoutConstructors = elements.filter({ !isConstructor($0) })
40
+ self.constructor = elements.lazy.compactMap(constructorDefinition).first
41
+ let elementsWithoutConstructors = elements.filter { constructorDefinition($0) == nil }
38
42
 
39
43
  super.init(definitions: elementsWithoutConstructors)
40
44
  }
@@ -169,13 +173,19 @@ extension SharedObject: ClassAssociatedObject {}
169
173
  // MARK: - Privates
170
174
 
171
175
  /**
172
- Checks whether the definition item is a constructor — a synchronous function whose name is "constructor".
176
+ Returns the definition item as a constructor, a synchronous function whose name is "constructor", or `nil`.
173
177
 
174
178
  We do it that way for the following two reasons:
175
179
  - It's easier to reuse existing `SyncFunctionDefinition`.
176
180
  - Redefining prototype's `constructor` is a bad idea so a function with this name
177
181
  needs to be filtered out when decorating the prototype.
178
182
  */
179
- private func isConstructor(_ item: AnyDefinition) -> Bool {
180
- return (item as? AnySyncFunctionDefinition)?.name == "constructor"
183
+ private func constructorDefinition(_ item: AnyDefinition) -> AnySyncFunctionDefinition? {
184
+ switch item._definitionClassification.kind {
185
+ case .function(let function), .staticFunction(let function):
186
+ // Only the element named "constructor" pays for the protocol cast.
187
+ return function.name == "constructor" ? function as? AnySyncFunctionDefinition : nil
188
+ default:
189
+ return nil
190
+ }
181
191
  }
@@ -2,6 +2,10 @@
2
2
  Represents a listener for the specific event.
3
3
  */
4
4
  internal struct EventListener: AnyDefinition {
5
+ var _definitionClassification: DefinitionClassification {
6
+ return DefinitionClassification(kind: .eventListener(self))
7
+ }
8
+
5
9
  let name: EventName
6
10
  let call: (Any?, Any?) throws -> Void
7
11