perf: use lzma-wasm for SWF decompression and drop vite
Replace the pure-JS lzma decoder with lzma-wasm (Rust/WASM, base64-inlined, zero-alloc decompress), giving an order-of-magnitude speedup on furni imports. Remove the obsolete lzma type shim and the redundant top-level vite dev dependency, which nothing imports directly.
This commit is contained in:
1 parent
7a41775c7e
commit
ca59a1065f
6 files changed
+19
-31
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { deflateSync } from "node:zlib";
|
||||
import LZMA from "lzma";
|
||||
import { initWasmSync, compress as lzmaCompress } from "lzma-wasm";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
decompressSwf,
|
||||
@@ -33,7 +33,10 @@ function cwsFixture(payload: Buffer, version = 6): Buffer {
|
||||
}
|
||||
|
||||
function zwsFixture(payload: Buffer, version = 6): Buffer {
|
||||
const rawLzma = LZMA.compress(payload, 9);
|
||||
initWasmSync();
|
||||
const rawLzma = Buffer.from(
|
||||
lzmaCompress(payload, { format: "lzma", level: 9 }),
|
||||
);
|
||||
const props = Buffer.from(rawLzma.slice(0, 5));
|
||||
const compressedPayload = Buffer.from(rawLzma.slice(13));
|
||||
const compressedSize = 5 + compressedPayload.length;
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
*/
|
||||
|
||||
import { inflateSync } from "node:zlib";
|
||||
import { initWasmSync, decompress as lzmaDecompress } from "lzma-wasm";
|
||||
|
||||
const LZMA = require("lzma/src/lzma_worker").LZMA_WORKER;
|
||||
initWasmSync();
|
||||
|
||||
// ── SWF Tag Types ──────────────────────────────────────────────────
|
||||
export const TAG_END = 0;
|
||||
@@ -62,7 +63,9 @@ export function decompressSwf(buffer: Buffer): Buffer {
|
||||
lzmaHeader.writeUInt32LE(0, 9);
|
||||
|
||||
const lzmaStream = Buffer.concat([lzmaHeader, compressedPayload]);
|
||||
const decompressed = Buffer.from(LZMA.decompress(lzmaStream) as number[]);
|
||||
const decompressed = Buffer.from(
|
||||
lzmaDecompress(lzmaStream, { expectedSize: uncompressedSize }),
|
||||
);
|
||||
|
||||
const header = Buffer.alloc(8);
|
||||
buffer.copy(header, 0, 0, 8);
|
||||
|
||||
Vendored
-14
@@ -1,14 +0,0 @@
|
||||
declare module "lzma" {
|
||||
export const LZMA: any;
|
||||
export function decompress(
|
||||
byte_array: any,
|
||||
on_finish?: (result: any, error: any) => void,
|
||||
on_progress?: (percent: number) => void,
|
||||
): any;
|
||||
export function compress(
|
||||
string: string | Uint8Array,
|
||||
mode: number,
|
||||
on_finish?: (result: any, error: any) => void,
|
||||
on_progress?: (percent: number) => void,
|
||||
): any;
|
||||
}
|
||||
Reference in new issue
Block a user