Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

perf(api): keep the bundle ASCII so V8 stores it one byte wide

Hampus20c7d9eda3a8
diff --git a/fluxer_api/scripts/build.mjs b/fluxer_api/scripts/build.mjs
index 0c743687e..70e8f1d45 100644
--- a/fluxer_api/scripts/build.mjs
+++ b/fluxer_api/scripts/build.mjs
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-import {readFileSync, rmSync} from 'node:fs';
+import {readdirSync, readFileSync, rmSync} from 'node:fs';
import {isBuiltin} from 'node:module';
import {dirname, join, resolve} from 'node:path';
import {fileURLToPath} from 'node:url';
@@ -45,7 +45,7 @@ await build({
platform: 'node',
format: 'esm',
target: 'node24',
- charset: 'utf8',
+ charset: 'ascii',
sourcemap: true,
sourcesContent: false,
logLevel: 'info',
@@ -53,6 +53,19 @@ await build({
plugins: [workspacePlugin],
});
+for (const file of readdirSync(OUT_DIR).filter((name) => name.endsWith('.js'))) {
+ const source = readFileSync(join(OUT_DIR, file), 'utf-8');
+ const index = source.search(/[\u0080-\uFFFF]/);
+ if (index !== -1) {
+ const line = source.slice(0, index).split('\n').length;
+ throw new Error(
+ `${file}:${line} contains a non-ASCII character. ` +
+ 'V8 stores a module source with any such character as a two-byte string, which doubles its memory. ' +
+ 'Write the character as a \\u escape.',
+ );
+ }
+}
+
if (undeclaredDependencies.size > 0) {
const names = [...undeclaredDependencies].sort().join(', ');
throw new Error(
diff --git a/packages/number_utils/src/PriceFormatting.ts b/packages/number_utils/src/PriceFormatting.ts
index 6481e1eef..5b6e26296 100644
--- a/packages/number_utils/src/PriceFormatting.ts
+++ b/packages/number_utils/src/PriceFormatting.ts
@@ -74,10 +74,10 @@ const HOME_COUNTRIES_BY_CURRENCY: Readonly<Record<string, ReadonlySet<string>>>
const STRIPE_TWO_DECIMAL_WHOLE_UNIT_CURRENCIES = new Set(['ISK', 'HUF', 'UGX']);
const RIGHT_TO_LEFT_LANGUAGES = new Set(['ar', 'he']);
-const BIDI_MARKS = /[‎‏؜]/g;
-const LEFT_TO_RIGHT_ISOLATE = '⁦';
-const POP_DIRECTIONAL_ISOLATE = '⁩';
-const NO_BREAK_SPACE = ' ';
+const BIDI_MARKS = /[\u200E\u200F\u061C]/g;
+const LEFT_TO_RIGHT_ISOLATE = '\u2066';
+const POP_DIRECTIONAL_ISOLATE = '\u2069';
+const NO_BREAK_SPACE = '\u00A0';
const localeByLowerCaseTag = new Map<string, LocaleCode>(
Object.values(Locales).map((locale) => [locale.toLowerCase(), locale]),