Why does scope(success) have to use exceptions?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jan 17 10:06:25 PST 2013


On Thu, Jan 17, 2013 at 06:20:56PM +0100, monarch_dodra wrote:
> On Thursday, 17 January 2013 at 16:05:05 UTC, Maxim Fomin wrote:
> >
> >DMD should optimize, but I was arguing that in this situation it
> >should not do this.
> 
> I *love* D's "scope".
> 
> It re-organizes some of the ugliest code I have ever seen into
> really beautiful code.

Yeah, not only so, but it also makes what would have been tricky
exception-safe code in C++ really easy to write, and easy to do so
*correctly*.


> However, having used it inside code that needs to run as fast as
> possible, I can tell you it is scary slow. As a matter of fact it
> was so scary slow one might even call it ridiculous. It *needs* to
> be improved if it wants to be taken seriously.

Well, there are a lot of areas in D that can use some implementation
improvements. :) The language construct itself is awesome; what we need
now is to make the implementation just as awesome.


> For non-inner loops, or non performance oriented operations, such as
> closing file hands, or for SQL transactions, I think it is fine.
> 
> However, don't use it in a loop. In particular, don't use it while
> decoding UTF!

For UTF, I've always believed in state-machine based directly
manipulation of UTF-8 (resp. -16, -32), ideally using a lexer generator
or regex engine or some such mechanism. Decoding into a dchar range
introduces painful amounts of overhead.

OTOH, if scope introduces extraneous overhead in loops, that's
definitely something to be looked at.

How does the performance of scope compare between DMD, GDC, and LDC?
Does GDC's superior optimizer reduce the overhead sufficiently? Or does
the front-end need improving?


T

-- 
Век живи - век учись. А дураком помрёшь.


More information about the Digitalmars-d mailing list