Skip to content

Default / lazy parser not cached #253

@Rafiot

Description

@Rafiot

I'm guessing I'm doing something wrong, because it makes very little sense when reading the doc but in short, on my machine, the slowest parser is ua-parser-rs.

That's what I'm doing in ipython (but I have the same results just with the python interpreter, it's just easier to time it):

from ua_parser import parse
ua_string = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36'

%timeit parse(ua_string).with_defaults()
  • With ua-parser-rs:

734 ms ± 27.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

  • With just google-re2

188 ms ± 10.9 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

  • After I uninstall ua-parser-rs and google-re2

1.07 ms ± 33.3 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

I'm on ubuntu 24.10 with Python 3.12.7.

Do you have any idea what's going on there? Something related to the cache being reloaded on every call? I couldn't find a way to avoid that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions