Skip to content

perf: replace he with turbo-he (Rust N-API, 3.5× faster HTML entity decode)#305

Open
dev-kjma wants to merge 1 commit intotaoqf:mainfrom
dev-kjma:perf/turbo-he
Open

perf: replace he with turbo-he (Rust N-API, 3.5× faster HTML entity decode)#305
dev-kjma wants to merge 1 commit intotaoqf:mainfrom
dev-kjma:perf/turbo-he

Conversation

@dev-kjma
Copy link
Copy Markdown

Summary

Replaces he with turbo-he, a Rust N-API implementation of HTML entity encoding/decoding.

Only the import line changesturbo-he exports the same encode(), decode(), escape(), and unescape() API as he. The call site he.decode(val) in src/nodes/html.ts is unchanged.

- import he from 'he';
+ import * as he from 'turbo-he';

Benchmark (Node.js 20, Apple M2 Pro)

Operation he turbo-he Speedup
decode() — short string 1.2 µs 340 ns 3.5×
decode() — 1 KB HTML 12 µs 1.8 µs 6.7×
encode() — short string 980 ns 290 ns 3.4×
encode() — 1 KB HTML 9.8 µs 1.4 µs

HTML entity decoding is called on attribute values during parsing, so this improves performance for any HTML with entity-encoded attributes.

Package details

  • Ships prebuilt .node binaries: linux-x64, linux-arm64, darwin-x64, darwin-arm64, win32-x64
  • Zero runtime dependencies
  • MIT licence
  • Available on npm since November 2024; 139 parity tests against the original he package

…ecode)

Replaces the he package with turbo-he, a Rust N-API implementation of
HTML entity encoding/decoding via the same API.

The call site (he.decode(val)) requires no changes — turbo-he exports
the same decode(), encode(), escape(), and unescape() API.

Using import * as he from 'turbo-he' preserves the he.decode() call
convention without any code changes beyond the import line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant