beyond-all-reason / spring

A powerful free cross-platform RTS game engine
https://beyond-all-reason.github.io/spring/
Other
198 stars 98 forks source link

Investigate using a faster Regex library #1181

Open bigbluejay9 opened 8 months ago

bigbluejay9 commented 8 months ago

Spring uses the std::regex library to perform regular expression operations.

std::regex is known to be quite slow https://github.com/HFTrader/regex-performance#results with potentially no path forward to improve its performance stack overflow, llvm discussion.

Spring has minimal dependencies on the std::regex library, which is exposed through https://github.com/beyond-all-reason/spring/blob/BAR105/rts/System/SpringRegex.h by re-exporting the std::regex* symbols.

Investigate replacing std::regex with a more performant library. Doing this when there are few dependencies should make the work somewhat more straightforward.

bigbluejay9 commented 7 months ago

CTRE, as the name implies, only supports compile time regular expressions. Spring mostly uses compile time constant regular expressions, with the key notable exception of globbing: https://github.com/beyond-all-reason/spring/blob/d01542dbad7627dc9a00b3d78e7fee3af7755e30/rts/System/FileSystem/FileSystem.cpp#L40, https://github.com/beyond-all-reason/spring/blob/d01542dbad7627dc9a00b3d78e7fee3af7755e30/rts/System/FileSystem/FileFilter.cpp#L130, https://github.com/beyond-all-reason/spring/blob/d01542dbad7627dc9a00b3d78e7fee3af7755e30/rts/System/FileSystem/FileSystemAbstraction.h#L126.

To use CTRE, we'd have to add support for globbing without regexes - either manually, or pulling in another library, e.g. https://github.com/p-ranav/glob and replacing calls to the real filesystem with calls to VFS.

bigbluejay9 commented 7 months ago

Other alternative regex libraries:

p2004a commented 7 months ago

Is there any heavy regex usage that justifies the cost of additional dependency?

bigbluejay9 commented 7 months ago

Not that significant, but it is the source of some slowness during loading. ~300ms from sampling (~4% of total load time).

before_regex_unmodified_BAR_branch

Mainly just investigating what it'll take to switch regex libraries. Even if we don't decide to it might be good to have a trail of what was previously tried.

Beherith commented 7 months ago

I think the engine depended on boost at some point, because even the mention of it gives me ptsd.

lhog commented 7 months ago

I like the CTRE + https://github.com/p-ranav/glob idea.