[D-runtime] foreach (dchar c; s) is too slow

Martin Nowak dawg at dawgfoto.de
Mon Sep 30 11:47:52 PDT 2013


The runtime support for string foreach with decoding has some serious 
performance issues.
It's currently implemented by creating a delegate for the foreach body 
and calling _aApply*.
I recently submitted this pull to vibe.d 
https://github.com/rejectedsoftware/vibe.d/pull/327.
Using the explicit for (auto tmp = s; !tmp.empty; tmp.popFront()) { auto 
c = tmp.front; /*CODE*/ }
is about 3 times faster.
I'd like to avoid such hidden performance pitfalls. Any ideas how to 
transition to templated library code?
For dchar iteration the compiler could simply prefer the range 
interface, but that wouldn't work for wchar (or char with w/dstrings).
Is it something that should only be added to phobos, e.g. foreach (c; 
s.byChar!dchar())?
Or should this be a combination of compiler and library support, i.e. 
when an explicit char type is given the compiler
instantiates a template with that char type.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d-runtime/attachments/20130930/70e9f944/attachment.html>


More information about the D-runtime mailing list