Issue 23737 - std.regex is slow to import and use
Summary: std.regex is slow to import and use
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-24 13:12 UTC by Richard (Rikki) Andrew Cattermole
Modified: 2023-06-16 01:24 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Richard (Rikki) Andrew Cattermole 2023-02-24 13:12:43 UTC
Right now std.regex is quite slow to import and use. Just importing it alone can add a few hundred milliseconds to your build times. This is most likely linked to std.uni and how it handles its tables decompression.

To use a simple regex pattern, adds 1s to your build times, however through some profiling and turning on bootstrap mode in std.uni there are some improvements to be had that will be quite significant.

First is the error method inside of Parser struct, remove formattedWrite.

Second is to stop trying to memorize the CharMatcher in wordMatcher. For some reason, this adds a lot of time that isn't required.

There are more things that can be done, but they don't appear to be big in terms of wins.
Comment 1 Richard (Rikki) Andrew Cattermole 2023-02-24 13:25:07 UTC
https://github.com/dlang/phobos/pull/8698

Only covers the removal of formattedWrite.

The problem with wordMatcher is that you actually want it to be memorized, so this particular bit of code is correct and desirable even if it slows down build times significantly, we may want improvements to CTFE engine instead as a solution to it.