You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I figured that the import of this library is very slow (500-1000ms on my system).
Given that the library probably less complex than e.g. numpy or similarly large packages: Do you think the import times can be optimized in some way?
On the other side, the import is a little slower than other libraries because it initializes some parser to be faster when executing it, so I think there isn't too much we can do.
On 13 July 2023 10:47:59 CEST, Simon Kern ***@***.***> wrote:
> dateparser 1.1.8 takes around 600ms to import here.
cannot replicate: `Elapsed context: 275 ms`
--
Reply to this email directly or view it on GitHub:
#533 (comment)
You are receiving this because you commented.
Message ID: ***@***.***>
I have to agree that hundreds of milliseconds are a problem. For me the import is about 250 ms and about 200 ms from that is the generation of _search_regex_ignorecase and related intermediate values at the end of timezone_parser.py:
(from that 140 ms is just _tz_offsets = list(build_tz_offsets(_search_regex_parts)), but that does not really matter).
From my point of view, it would be better not to precompute this list on import, but rather do so on first use of pop_tz_offset_from_string which is the only function using it. That way the import time would be significantly shortened and the overall running time of an app using the pop_tz_offset_from_string function won't be affected.
Would it be interesting for you if I attempted this change and sent a pull request?
Reacted by Simon Kern, Sridaran Thoniyil and Mike Lissner
OK, I created an MR for this issue. It postpones the compilation of regexps in timezone_parser.py and reduces the import time to about 20 % of the original import time.
I have reverted #1250 in 1.4.0 due to security concerns about the approach. Reopening this now so that we can look at alternative approaches not involving pickle.
Activity
noviluni commentedon May 20, 2020
Hi @skjerns , could you confirm that this is happening with the last version? I can't reproduce it.
noviluni commentedon May 20, 2020
On the other side, the import is a little slower than other libraries because it initializes some parser to be faster when executing it, so I think there isn't too much we can do.
skjerns commentedon May 20, 2020
@noviluni it's faster now (280ms), but I've also upgraded my PC, so I can't really tell ;-)
using
python: 100ms (kind of acceptable)using
ipython: 280ms (this is still slower thanscipyornumpy)Maybe you could implement some lazy loading to the parsers? Or are they all needed?
noviluni commentedon Nov 26, 2020
I tried with the last version of
dateparser(1.0.0) and it takes less time thanpandas, so I think it shouldn't be considered an issue.I will close it. Feel free to comment or reopen it if you thing there is something that should be improved 🙂
skjerns commentedon Nov 27, 2020
Yes! Seems to be much faster now :) thanks alot!
Natureshadow commentedon Jul 3, 2023
dateparser 1.1.8 takes around 600ms to import here.
skjerns commentedon Jul 13, 2023
cannot replicate:
Elapsed context: 275 mson v1.1.8Natureshadow commentedon Jul 13, 2023
beda42 commentedon Aug 11, 2023
I have to agree that hundreds of milliseconds are a problem. For me the import is about 250 ms and about 200 ms from that is the generation of
_search_regex_ignorecaseand related intermediate values at the end oftimezone_parser.py:(from that 140 ms is just
_tz_offsets = list(build_tz_offsets(_search_regex_parts)), but that does not really matter).From my point of view, it would be better not to precompute this list on import, but rather do so on first use of
pop_tz_offset_from_stringwhich is the only function using it. That way the import time would be significantly shortened and the overall running time of an app using thepop_tz_offset_from_stringfunction won't be affected.Would it be interesting for you if I attempted this change and sent a pull request?
beda42 commentedon Sep 7, 2023
OK, I created an MR for this issue. It postpones the compilation of regexps in
timezone_parser.pyand reduces the import time to about 20 % of the original import time.Any feedback is welcome.
feat: add caching for timezone offsets, significantly speeds up import
feat: add caching for timezone offsets, significantly speeds up import
feat: add caching for timezone offsets, significantly speeds up import
feat: add caching for timezone offsets, significantly speeds up import
feat: add caching for timezone offsets, significantly speeds up import
feat: add caching for timezone offsets, significantly speeds up import
feat: add caching for timezone offsets, significantly speeds up import
feat: add caching for timezone offsets, significantly speeds up import
feat: add caching for timezone offsets, significantly speeds up import
feat: add caching for timezone offsets, significantly speeds up import
feat: add caching for timezone offsets, significantly speeds up import
feat: add caching for timezone offsets, significantly speeds up import
feat: add caching for timezone offsets, significantly speeds up import (
AdrianAtZyte commentedon Mar 26, 2026
I have reverted #1250 in 1.4.0 due to security concerns about the approach. Reopening this now so that we can look at alternative approaches not involving pickle.