go-dateparser icon indicating copy to clipboard operation
go-dateparser copied to clipboard

Too much memory allocated.

Open fotock opened this issue 1 year ago • 1 comments

Without this dateparser, my service takes 5M memory. It takes 50M after I use this date parser to parse dates.

My question is, why it takes so much memory and, if possible, how to minimise the memory allocation of this module? Thanks.

fotock avatar Mar 06 '25 05:03 fotock

Thanks for the report. This is a known issue. The problem occurs because dateparser uses a lot of regular expressions -- almost 4,000! -- across all locales. All of them are compiled at initialization time, which leads to high memory usage. For reference, in my benchmark, this package uses around 24 MB just for initializing the regex.

Image

Unfortunately, there's nothing you, as an end user, can do, since the regex compilation happens during initialization, not during parsing.

I do have plans to pre-compile the regex using something like re2go, but I haven’t had the time or resources to work on it yet. I’ll keep this issue open to track it.

RadhiFadlillah avatar Apr 08 '25 12:04 RadhiFadlillah