dateparser icon indicating copy to clipboard operation
dateparser copied to clipboard

DateDataParser caching

Open brl0 opened this issue 2 years ago • 0 comments

Splitting out from my comment in #939:

Also, while I haven't yet tried using this at scale, I wonder if the dateparser.parse function might have some opportunity for performance improvement by not instantiating the DateDataParser class on each call, one possible (untested) approach might be something like the following:

from functools import lru_cache

@lru_cache
def get_ddp(**kwargs):
    return DateDataParser(**kwargs)

And here was the response from @noviluni:

If you check the dateparser/dateparser/init.py file, you will see that there's a "default_parser" to avoid instantiating it every time:

_default_parser = DateDataParser()

So it's only instantiated when we find languages, locales, region or the settings doesn't have the default value:

    if languages or locales or region or not settings._default:
        parser = DateDataParser(languages=languages, locales=locales,
                                region=region, settings=settings)

However, it could be possible that we use dateparser.parse() with the same settings, languages, etc. multiple times, so maybe we could cache also this.

brl0 avatar Jul 24 '21 19:07 brl0