scrapinghub / scrapinghub/dateparser

DateDataParser caching

Open
#950 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
520
Avg merge
22h 56m
Merged PRs (30d)
6

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with dateparser/dateparser/init.py and the dateparser.parse entry point, especially _default_parser and the branch that constructs DateDataParser. Measure repeated calls with identical languages, locales, region, and settings, then verify that any caching preserves parsing behavior and improves the relevant case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.