Skip to content

Commit 76da264

Browse files
perf(mobile): highlight code with native @pierre/highlights instead of Shiki (#24544)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 3cc31ed commit 76da264

65 files changed

Lines changed: 118377 additions & 1963 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.macroscope/ignore.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,8 @@ infra/relay/migrations/**/snapshot.json
274274
# Ghostty build output vendored from upstream.
275275
apps/mobile/modules/t3-terminal/Vendor/**
276276
native/libghostty-vt/include/**
277+
278+
# @pierre/highlights compiled to C by wasm2c, plus the wasm2c runtime and simde
279+
# it needs. Regenerated by apps/mobile/scripts/generate-highlights.mts; review
280+
# that script and cpp/t3_highlights.c instead.
281+
apps/mobile/modules/t3-highlights/Vendor/**

‎apps/mobile/.swiftlint.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
included:
22
- ios/T3Code
33
- modules/t3-composer-editor/ios
4+
- modules/t3-highlights/ios
45
- modules/t3-native-controls/ios
56
- modules/t3-terminal/ios
67
- modules/t3-review-diff/ios

‎apps/mobile/README.md‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,6 @@ Build and run the local iOS preview app:
9696
vp run ios:preview
9797
```
9898

99-
Force the review diff highlighter engine:
100-
101-
```bash
102-
EXPO_PUBLIC_REVIEW_HIGHLIGHTER_ENGINE=javascript vp run ios:dev
103-
```
104-
105-
`javascript` is the default and recommended setting for the review diff screen. Set `EXPO_PUBLIC_REVIEW_HIGHLIGHTER_ENGINE=native` only when you explicitly want to test the native Shiki engine.
106-
10799
Inspect the resolved Expo config for a variant:
108100

109101
```bash

‎apps/mobile/app.config.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,6 @@ const config: ExpoConfig = {
454454
...(!isIosPersonalTeamBuild ? ["./plugins/withWidgetLogoAsset.cjs", widgetsPlugin] : []),
455455
"./plugins/withAndroidCleartextTraffic.cjs",
456456
"./plugins/withAndroidGradleHeap.cjs",
457-
"./plugins/withAndroidFbjniVersion.cjs",
458457
"./plugins/withAndroidInputBackground.cjs",
459458
"./plugins/withAndroidModernPopupMenu.cjs",
460459
"./plugins/withAndroidModernAlertDialog.cjs",

‎apps/mobile/metro.config.js‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,8 @@ const licenseGeneratorSource = path.join(
1616
"third-party-licenses.ts",
1717
);
1818
const escapedWorkspaceRoot = workspaceRoot.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
19-
const mobileShikiRoot = path.dirname(require.resolve("shiki/package.json", { paths: [__dirname] }));
2019
const generatedDeviceStreamRoot = path.join(__dirname, ".generated", "device-stream");
2120
const generatedPreviewStreamRoot = path.join(__dirname, ".generated", "preview-stream");
22-
const resolveShikiDependencyRoot = (packageName) => {
23-
const entryPath = require.resolve(packageName, { paths: [mobileShikiRoot] });
24-
let currentDir = path.dirname(entryPath);
25-
26-
while (!fs.existsSync(path.join(currentDir, "package.json"))) {
27-
const parentDir = path.dirname(currentDir);
28-
if (parentDir === currentDir) {
29-
throw new Error(`Could not resolve package root for ${packageName}`);
30-
}
31-
currentDir = parentDir;
32-
}
33-
34-
return currentDir;
35-
};
3621

3722
config.watchFolders = [...new Set([...(config.watchFolders ?? []), workspaceRoot])];
3823
config.resolver = {
@@ -50,14 +35,6 @@ config.resolver = {
5035
"@t3tools/mobile-third-party-licenses": generatedLicenseModuleRoot,
5136
"@t3tools/mobile-device-stream": generatedDeviceStreamRoot,
5237
"@t3tools/mobile-preview-stream": generatedPreviewStreamRoot,
53-
shiki: mobileShikiRoot,
54-
"@shikijs/core": resolveShikiDependencyRoot("@shikijs/core"),
55-
"@shikijs/engine-javascript": resolveShikiDependencyRoot("@shikijs/engine-javascript"),
56-
"@shikijs/engine-oniguruma": resolveShikiDependencyRoot("@shikijs/engine-oniguruma"),
57-
"@shikijs/langs": resolveShikiDependencyRoot("@shikijs/langs"),
58-
"@shikijs/themes": resolveShikiDependencyRoot("@shikijs/themes"),
59-
"@shikijs/types": resolveShikiDependencyRoot("@shikijs/types"),
60-
"@shikijs/vscode-textmate": resolveShikiDependencyRoot("@shikijs/vscode-textmate"),
6138
},
6239
};
6340

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'json'
2+
3+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4+
5+
Pod::Spec.new do |s|
6+
s.name = 'T3HighlightsNative'
7+
s.version = package['version']
8+
s.summary = 'Native @pierre/highlights syntax highlighter for T3 Code mobile.'
9+
s.description = 'Runs the @pierre/highlights lexers, compiled from WebAssembly to C with wasm2c.'
10+
s.homepage = 'https://t3tools.com'
11+
s.license = { :type => 'UNLICENSED' }
12+
s.author = { 'T3 Tools' => '[email protected]' }
13+
s.platforms = { :ios => '16.1' }
14+
s.source = { :path => '.' }
15+
s.source_files = 'ios/**/*.swift', 'cpp/**/*.{c,h,inc}', 'Vendor/**/*.{c,h,inc}'
16+
# Swift sees only the wrapper; the generated and runtime headers stay private.
17+
s.public_header_files = 'cpp/t3_highlights.h'
18+
# Debug builds compile at -O0 by default, which makes the lexers several times
19+
# slower. They are generated code, so optimize them in every configuration.
20+
s.compiler_flags = '-O2'
21+
s.pod_target_xcconfig = {
22+
'DEFINES_MODULE' => 'YES',
23+
# Plain malloc memory with explicit bounds checks: no guard-page signal
24+
# handlers competing with the app's crash reporting.
25+
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) WASM_RT_USE_MMAP=0 WASM_RT_MEMCHECK_BOUNDS_CHECK=1 WASM_RT_SKIP_SIGNAL_RECOVERY=1',
26+
'HEADER_SEARCH_PATHS' => '$(inherited) "${PODS_TARGET_SRCROOT}/Vendor" "${PODS_TARGET_SRCROOT}/Vendor/highlights" "${PODS_TARGET_SRCROOT}/Vendor/wasm2c"',
27+
}
28+
s.swift_version = '5.9'
29+
s.dependency 'ExpoModulesCore'
30+
end

0 commit comments

Comments
 (0)