Repository navigation
perf(runtime): shrink ada, parse URLs once, fix URLPattern groups - #2152
Conversation
ada was built at the runtime-wide -O3. At -Os its code shrinks by about 50 KB per ABI; on a Galaxy S20 FE and a Galaxy S8, absolute/relative/IDN parses got 7-19% slower (tens of nanoseconds each) and URLSearchParams 2-3% faster.
new URL(input, base) called ada::can_parse, which parses base and input, then parsed both again; it now parses each once. URL.canParse uses ada::parse too, so ada::can_parse and its second parser instantiation are no longer linked. canParse now stringifies its arguments instead of casting them to strings unchecked, ignores an undefined base, and keeps an embedded NUL; new URL() without arguments throws a TypeError; and a base whose toString() throws propagates the exception instead of aborting.
v8_regex_provider::regex_search returned RegExp.exec's whole match as the first capture, so every named group read its predecessor's value (the first one the whole match) and ada paired one more result than it has group names. The hasRegExpGroups getter was registered as hasRegexpGroups. Both match iOS now.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Description
Stacked on #2134 (Ada 4.1.1). This is the Android half of NativeScript/ios#606.
As #2134 stands, the upgrade adds about 89 KB per ABI to
libNativeScript.so. This PR takes back most of that.1. Build ada at
-Os. ada was compiled at the runtime-wide-O3. At-Os, ada's code is about 50 KB smaller per ABI. Native benchmark on two phones (median of 3 rounds, ns per operation):-O3-Os-O3-OsThe slowdown is tens of nanoseconds per
new URL(). Onlyada.cppchanges; the rest of the runtime stays at-O3, and local Debug builds are unaffected.2. Parse each URL once.
new URL(input, base)calledada::can_parse(input, &base), which parses both, then parsed both again. It now parses each once.URL.canParseusesada::parseas well, soada::can_parseand its second parser instantiation are no longer linked.canParsestringifies its arguments instead of casting them tov8::Stringunchecked, soURL.canParse(urlObject)no longer reads a non-string as a string;canParsetreats an undefined base as absent and no longer truncates at an embedded NUL;new URL()without arguments throws aTypeErrorinstead of readingundefinedas a string;toString()throws now propagates the exception instead of aborting inToLocalChecked().3. URLPattern capture groups and
hasRegExpGroups. Found while adding specs:testURLPattern.jswas neverrequired frommainpage.js, so the Android URLPattern specs never ran. Once registered, they exposed two bugs:v8_regex_provider::regex_searchreturnedRegExp.exec's whole match as the first capture. Every named group read its predecessor's value, so:idin/books/:idgot/books/123. ada also received one more result than it has group names. iOS already skips element 0.hasRegExpGroupsgetter was registered ashasRegexpGroups.Both now match iOS, and the specs now cover
test()/exec()with capture groups.Size. arm64
optimizedbuild. Numbers are loaded bytes from thelldlink map (code, rodata, data, unwind), because stripped.sosizes are page-rounded.libNativeScript.so-fdata-sectionsfrom #2136Not ported from iOS:
-fvisibility=hiddenand a version script. The equivalent loss here came from-fno-data-sections: it put every ada vtable in one section, so unused code like theada::urlparser stayed linked. build: keep the NDK's default compile flags #2136 removes that flag.libicu.soexists only from API 31 and ships nouidna.h. The only system UTS error handling: #46 is Java'sandroid.icu.text.IDNA(API 24+, ICU 56 / Unicode 8 at the bottom of the range), which would need JNI. Left out.std::regex. The Android runtime has nostd::regexuse; URLPattern already runs on V8's RegExp.Does your commit message include the wording below to reference a specific issue in this repo?
No.
Related Pull Requests
-fno-data-sections; together they reach the last size row aboveDoes your pull request have unit tests?
Yes. The full suite passes on an API 36 arm64 emulator: 1,792 specs, 0 failures.
testURLPattern.jsnow runs, and new specs cover:URLbases;toString();new URL()without arguments;URL.canParsewith string,URL-object and undefined arguments;xn--, ZWJ rejection);test()/exec()with capture groups.Summary by CodeRabbit
Bug Fixes
URL.canParse()to validate inputs and optional bases consistently.hasRegExpGroupsproperty name.Tests