Slow code, slow

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Feb 26 20:05:00 UTC 2018


On Mon, Feb 26, 2018 at 09:03:14PM +0200, ketmar via Digitalmars-d wrote:
> H. S. Teoh wrote:
[...]
> > In my mind, even C's printf API is sucky, because it involves runtime
> > parsing of what's usually a static string, over and over again. What we
> > *really* want is for something like:
> > 
> > 	writeln("blah %d bluh %s", i, s);
> > 
> > to be translated into something like:
> > 
> > 	stdout.putString("blah ");
> > 	stdout.putInt(i);
> > 	stdout.putString(" bluh ");
> > 	stdout.putString(s);
[...]
> i once wrote such thing (for fun, using "Functional Programming With
> Templates"). it was fun to do, and freakin' slow due to template
> bloat. ;-)
> but yes, it generates a string mixin, and in runtime there was no
> format string parsing.

The problem is not the Phobos implementation.  The problem is that the
compiler's way of handling templates and CTFE needs to be improved.  We
seriously need to muster some manpower to help Stefan finish newCTFE,
and then we need to take a serious look at improving the current
implementation of templates.


> still, we can be either smart, or have fast compile times, but not
> both. T_T
[...]

I'll like to disagree. :-D  There's got to be a way to do this that
doesn't have to compromise either way.  I mean, this is not like we're
doing rocket science here, or solving an NP complete problem.  It's a
straightforward way of recognizing a particular code pattern and
applying 1-to-1 mappings.  The general case of completely arbitrary
templates can still fallback to the current implementation.  The point
is to optimize for specific template usage patterns that are common and
yields big speedups, but still leave the door open for weirder, but less
common, template code.


T

-- 
Fact is stranger than fiction.


More information about the Digitalmars-d mailing list