January 17, 2013
Am Thu, 17 Jan 2013 13:15:06 +0100
schrieb "Maxim Fomin" <maxim@maxim-fomin.ru>:

> On linux, segfaults can be translated into exceptions using this module (https://github.com/D-Programming-Language/druntime/blob/master/src/etc/linux/memoryerror.d) however I do not know how to use it - I get linker errors.
> 
> On windows null pointer errors are translated into Object.Error (Access Violation) - I do not remember exactly.
> 
> In any case, your void callScope(ref int x) can be blown up by:
> int* ptr; callScope(*ptr); so, exceptions may come when they are
> not expected.

Uh, does that meany that a D compiler can never optimize by removing exception handling, even if it can prove that all involved methods are nothrow and don't throw errors as well?
January 17, 2013
On 1/17/13, Maxim Fomin <maxim@maxim-fomin.ru> wrote:
> In any case, your void callScope(ref int x) can be blown up by:
> int* ptr; callScope(*ptr); so, exceptions may come when they are
> not expected.

That was the point of the sample code, exceptions can be thrown at any point and as a result the stack will unwind, hence the compiler can rewrite callScope to look like callFunc. This isn't about the *lack* of exceptions being thrown.
January 17, 2013
On Thursday, 17 January 2013 at 15:35:26 UTC, Andrej Mitrovic wrote:
> On 1/17/13, Maxim Fomin <maxim@maxim-fomin.ru> wrote:
>> In any case, your void callScope(ref int x) can be blown up by:
>> int* ptr; callScope(*ptr); so, exceptions may come when they are
>> not expected.
>
> That was the point of the sample code, exceptions can be thrown at any
> point and as a result the stack will unwind, hence the compiler can
> rewrite callScope to look like callFunc. This isn't about the *lack*
> of exceptions being thrown.

Well, with success scope statement it seems you are right - compiler can optimize it in cases like this because if exception is thrown when assigning 1 to x, no further statements should be performed within callScope.
January 17, 2013
On Thursday, 17 January 2013 at 15:16:07 UTC, Johannes Pfau wrote:
> Am Thu, 17 Jan 2013 13:15:06 +0100
> schrieb "Maxim Fomin" <maxim@maxim-fomin.ru>:
>
>> On linux, segfaults can be translated into exceptions using this module (https://github.com/D-Programming-Language/druntime/blob/master/src/etc/linux/memoryerror.d) however I do not know how to use it - I get linker errors.
>> 
>> On windows null pointer errors are translated into Object.Error (Access Violation) - I do not remember exactly.
>> 
>> In any case, your void callScope(ref int x) can be blown up by:
>> int* ptr; callScope(*ptr); so, exceptions may come when they are not expected.
>
> Uh, does that meany that a D compiler can never optimize by removing
> exception handling, even if it can prove that all involved methods are
> nothrow and don't throw errors as well?

DMD should optimize, but I was arguing that in this situation it should not do this.
January 17, 2013
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.

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.

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!
January 17, 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

-- 
Век живи - век учись. А дураком помрёшь.
1 2
Next ›   Last »