Regex matching cause lots of _d_arrayliteralTX calls

Dmitry Olshansky dmitry.olsh at gmail.com
Fri Sep 27 07:37:00 PDT 2013


27-Sep-2013 02:00, JR пишет:
> I'm working on a toy IRC bot. Much of the logic involved is translating
> the incoming raw IRC string into something that makes sense (so now I
> have two problems, etc). But I managed to cook up a regex that so far
> seems to work well. Time for callgrind!
>
> Grouped by source file, most time is spent in regex.d (as would seem
> natural) but more time is spent in gc.d than I would have expected.
> Looking at the callgraph I see that there's a curious amount of calls to
> _d_arrayliteralTX from (around) where the regex matching is done.
> (There's some inlining going on.)
>
> Example:   http://dpaste.dzfl.pl/3932a231 (needs dmd head)
>

And the answer is - don't use ENUM with ctRegex.
The problem is that ctRegex returns you a pack of datastructures (=arrays).
Using them with enum makes it behave as if you pasted them as array 
literals and these do allocate each time.

TL;DR: use static and/or auto with ctRegex not enum.

-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list