From b7b82c10f75dacd86ce154e540ae8664855d2ff1 Mon Sep 17 00:00:00 2001 From: masklinn Date: Tue, 31 Mar 2026 22:08:41 +0200 Subject: [PATCH] Always cache resolvers After getting access to a second dataset which is a lot more cache-friendly than the original (while also being a real-world sample), I think it makes sense to cache the "fast" resolvers as well: going back to the original commit (b45380d348af5fc52b96dc1b8ae0bbeea569b336) an S3Fifo(5000) was estimated to take about 3.5MB when full (0.5MB of cache metadata, and 3MB of actual cached data), so an S3Fifo(2000) would be about 1.5MB or thereabouts which is not nothing... but is pretty much nothing compared to the RSS impact of the advanced parsers. Fixes #302 --- src/ua_parser/__init__.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/ua_parser/__init__.py b/src/ua_parser/__init__.py index 5b5ba71..844aac9 100644 --- a/src/ua_parser/__init__.py +++ b/src/ua_parser/__init__.py @@ -68,14 +68,7 @@ if importlib.util.find_spec("ua_parser_rs"): from .regex import Resolver as RegexResolver BestAvailableResolver: _ResolverCtor = next( - filter( - None, - ( - RegexResolver, - Re2Resolver, - lambda m: CachingResolver(BasicResolver(m), Cache(2000)), - ), - ) + filter(None, (RegexResolver, Re2Resolver, BasicResolver)) ) @@ -97,7 +90,7 @@ def from_matchers(cls, m: Matchers, /) -> Parser: stack. """ - return cls(BestAvailableResolver(m)) + return cls(CachingResolver(BestAvailableResolver(m), Cache(2000))) def __init__(self, resolver: Resolver) -> None: self.resolver = resolver