Add native batch text URL rewrite API#282
Open
adamziel wants to merge 4 commits into
Open
Conversation
This was referenced May 18, 2026
4903777 to
684a29c
Compare
Collaborator
Author
|
Rebased this stack on current Sample: 5,000
This did not confirm the hypothesis that the stacked native batch text rewrite has no meaningful improvement after #283. It is still materially faster on this content sample. Caveat: the rebased native-extension CI is currently failing URL text parity tests in the native-extension job, so this stack is not merge-ready as-is. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it does
Adds
wp_native_apis_rewrite_text_url_bases()to thewp_native_apisextension. The function rewrites URL bases across a whole text value in one native call using a compactfrom\x1fto\x1e...mapping string.Rationale
Reprint currently has to drive URL detection and replacement from PHP one URL at a time. In PHP.wasm, that keeps the hot URL rewrite path split across many PHP/native boundary crossings. This adds a coarse native primitive that can rewrite one decoded value in a single call.
Implementation
The host PHP extension exposes the function through the Rust-backed
ext-php-rsmodule and reuses the existing Rust URL-in-text candidate scanner and validation logic. It applies base URL replacements in one pass over the original text and preserves bare-domain and protocol-relative URL forms.The PHP.wasm extension still builds through
native_apis_shim.c, so this PR also adds the same public function to that C shim. That gives Playground/Reprint a real PHP.wasm fast path instead of only smoke-test classes.The verifier and Playground smoke blueprint now check that the extension registers the function and that a simple base replacement works.
Benchmarks
Measured from Reprint PR adamziel/reprint#216, CI run https://github.com/adamziel/reprint/actions/runs/26067523070/attempts/3.
Focused case:
StructuredDataUrlRewriterrewrites 10,000 URLs across 556,690 scanned bytes.These are single-run CI measurements, so treat them as directional.
Testing instructions
Run locally:
Local results from this branch:
I could not build the PHP extension locally because this environment has no
php-configand no package manager to install PHP development headers. GitHub Actions builds and verifies both the host PHP extension and the PHP.wasm extension.