Repository navigation
Geodata: Reduce matcher memory on mobile and desktop, skip regexes that cannot match - #6867
Conversation
|
完了,这下核武器真的从地里自己冒出来了。我 review 不了这个 PR 了 |
|
thanks. that copy is already gone here: the group's Match returns a fresh slice and MphValueMatcher and MphIndexMatcher hand it on as is instead of going through CompositeMatches. TestMphDomainMatcher_MatchReturnsDetachedSlice still passes, and there is a new test that clears a returned slice and checks the next result the loader, mobile and regex commits are in here now too, as Fangliding asked, so it can be read one commit at a time. every commit was checked against MatchAny/Match results recorded on main for 10 lists x 6 workloads, about 1.2M lookups |
|
我看到了你把 CompositeMatches 拿掉了 |
|
checked every path. the mph part is a new slice per call, and the ac and regex parts are appended into it rather than returned, so even when only the keyword part matches (CompositeMatchesReverse hands out ac's own slice there) append copies it into a fresh one. LinearValueMatcher keeps CompositeMatches' clone, and on mobile MphSetGroup builds its result per call and appends it to that clone I added TestDomainMatcher_MatchResultsCanBeSortedConcurrently: full, domain, keyword, regex and geosite rules on both factories, each result overwritten up to its capacity before matching again, and 8 goroutines sorting results in place like dns does. it passes under -race and fails if the keyword slice or a single custom part escapes without a copy |
3c103da to
4b14911
Compare
|
I’ve finished reviewing everything except the perfect hashing implementation. Reviewing the abstractions was honestly a bit painful, because I’d pretty much forgotten my own original design. Could we rename For We can keep the current file layout and implementation—just clarify the names. |
|
renamed as you suggested: CompactMphDomainMatcherFactory, CompactMphDomainMatcher and MphValueMatcherCombiner, and the field holding it is combiner now |
|
@RPRX 建议尽早发版测试,iOS 重大利好 |
|
|
国庆能发正式版吗 |
|
net/http 包现在是练习时长不到两年半的 junior 接手 |
|
够呛 |
|
这个PR优化的挺好的,内存降低了挺多的 |
follow-up to #6821, with the rest of the geodata work kept together as Fangliding asked on #6868. the commits read on their own. the first stores one record per distinct pattern in MphMatcherGroup, in a byte arena behind a 0.99-load hash/displace/compress table with 4-byte slots and a 1-byte fingerprint, hashed right to left by a deterministic polynomial so one pass gives every parent domain. the second decodes geosite categories with protowire straight from the read buffer instead of going through []*Domain. the third makes ios and android build each category as an MphValueMatcher instead of the map-based trie, with MphValueMatcherCombiner hashing the input once per list. the fourth gives regexes a guard of the bytes a match can end with, so most misses never run the regexp
a typical desktop config goes from 33.6 to 11.4 MB, and on an iPhone ads + cn + !cn from +62 to +10 MiB of phys_footprint. hits get 1.5-1.7x faster on the phone, misses on regex-heavy lists about 40% and lookups reaching PRIVATE about 80%. the in-repo group-level Match benchmarks are 7-15% slower because Match now decodes values into its own slice, which MphValueMatcher hands on without the extra copy. on mobile the answers now equal desktop on rule shapes that Loyalsoldier and dlc don't contain (leading-dot or empty domain rules, keywords)
desktop memory, main -> this PR
Loyalsoldier geosite.dat, Ryzen 9 5900X, go1.27.0, GOMAXPROCS=4, fresh process per cell, median of 3, desktop factory with the first three commits (the regex commit does not change memory)
all3 = ads + cn + !cn in one list, typical = router [ads], [cn], [!cn] + DNS [cn, !cn]
iPhone, ads + cn + !cn, main -> this PR
ios/arm64, go1.27.1, a plain gomobile app (same phys_footprint ledger as an extension), one run per launch, 3-4 runs each
lookups, desktop, paired A/B vs main, median ns/op
each block measures that commit alone against main; answers identical on every sample
correctness