Skip to content

Add native plain text literal URL rewrites#285

Open
adamziel wants to merge 1 commit into
trunkfrom
codex/native-plain-text-literal-url-rewrite
Open

Add native plain text literal URL rewrites#285
adamziel wants to merge 1 commit into
trunkfrom
codex/native-plain-text-literal-url-rewrite

Conversation

@adamziel
Copy link
Copy Markdown
Collaborator

What changed

Adds wp_native_apis_rewrite_plain_text_literal_urls() to the native APIs extension for known plain-text leaf values.

The new primitive accepts compact source-origin\x1ftarget-prefix rows separated by \x1e, rewrites HTTP(S) source-origin matches, and returns false instead of guessing when a value contains structured-data delimiters or a source-origin match is not bounded as a URL origin.

Why

Reprint now has a rigorous PHP plain-text literal fast path, but that path still runs for hundreds of thousands of SQL values under PHP.wasm. Moving the narrow, parser-owned leaf rewrite into the native extension cuts that hot path without reintroducing naive URL replacement in structured containers.

Benchmarks

PHP.wasm 8.4.21, native APIs extension built from this branch, 2,000 iterations of the new plain-text-literal-url-rewrite benchmark workload:

implementation operations wall time throughput speedup
PHP 720,000 0.702 s 1.03M ops/s 1.0x
Native 720,000 0.177 s 4.07M ops/s 4.0x

Reprint large SQL rewrite-only profile, 262 MB dump, both PHP.wasm native manifests loaded:

path total rewrite profile plain literal rewrite bucket
PHP literal fallback 7.53 s 1.86 s
Native literal function 6.45 s 0.83 s

Validation

  • cargo test -q in extensions/native-apis
  • vendor/bin/phpcs -d memory_limit=1G bin/benchmark-native-apis.php extensions/native-apis/tests/verify-native-apis.php
  • php -l extensions/native-apis/tests/verify-native-apis.php && php -l bin/benchmark-native-apis.php
  • RUSTFLAGS='-C link-arg=-undefined -C link-arg=dynamic_lookup' extensions/native-apis/build-extension.sh
  • php -d extension=$(pwd)/extensions/native-apis/target/release/libwp_native_apis.dylib extensions/native-apis/tests/verify-native-apis.php
  • extensions/native-apis/build-playground-extension.sh /Users/cloudnik/conductor/workspaces/studio/amsterdam/.context/wasm-extensions/php-toolkit-native-literal
  • PHP.wasm smoke test for wp_native_apis_rewrite_plain_text_literal_urls() using the built manifest

composer lint still reports existing repository-wide warnings unrelated to this PR; the changed PHP files pass PHPCS directly.

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