November 10, 2021
On Wednesday, 10 November 2021 at 06:47:32 UTC, forkit wrote:

> btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache. So I really don't give a damn about allocations .. not one little bit ;-)

That's not the point. The point is the program is doing unnecessary non-trivial work while introducing additional failure paths. It certainly has ways to go to reach Ali's AA solution, but still...

To put things in perspective, the algorithm can easily complete before malloc even returns (heck, before it even starts executing). There's what, 11 cmovs at most? It would take several dozen instructions, a couple of loops and a few other branches just to find malloc when you first call it. Not to mention it itself making that syscall and setting up its bins...

And I'm not even talking about optimization. Just, uh, non-pessimization.
November 10, 2021
On Wednesday, 10 November 2021 at 06:47:32 UTC, forkit wrote:
> btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache. So I really don't give a damn about allocations .. not one little bit ;-)

It's not a good mindset to have

Give room for the unexpected, don't burn all of your options right now

Having good foundation helps one to grow and scale faster than others

Often i seen gamedevs write shitty code, "it's fine" they said, only to realize their game runs at 10FPS when they decide it's time to port it to the Switch (portable console) or when one decide to play on a laptop

Or your server can no longer fit in the 128mb VPS instance, and you forced to pay the more expensive one, only because "it was fine"


Having the right mindset helps not make these mistakes in the future

Changing habits is hard, make sure to train yourself to pick the right one, early if possible

November 10, 2021
On Wed, Nov 10, 2021 at 10:17:48PM +0000, russhy via Digitalmars-d-learn wrote:
> On Wednesday, 10 November 2021 at 06:47:32 UTC, forkit wrote:
> > btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache. So I really don't give a damn about allocations .. not one little bit ;-)
> 
> It's not a good mindset to have
> 
> Give room for the unexpected, don't burn all of your options right now
> 
> Having good foundation helps one to grow and scale faster than others
[...]

+1.

Ironically, dmd itself is pretty care-free about allocating memory (in the name of compile speed -- after all, everybody has GBs of RAM to spare, but nobody wants to wait, right?). As a result, I cannot compile even simple programs on a low-memory system because the compiler runs out of memory and crashes before it can finish compiling.  What good is a super-fast compiler that cannot finish compiling before it uses too much memory?  Because of this, I have not dared to introduce D to my colleagues -- if they see what dmd does on the kind of low-memory embedded systems that we work on, they'd get such a bad impression of D they'll never ever want to hear about it again. :-/


T

-- 
Verbing weirds language. -- Calvin (& Hobbes)
November 10, 2021
On 11/10/21 3:05 PM, H. S. Teoh wrote:

> I cannot compile
> even simple programs on a low-memory system because the compiler runs
> out of memory

Did the -lowmem switch help in some cases?

Is -betterC any better? ;)

Ali

November 10, 2021
On Wednesday, 10 November 2021 at 22:17:48 UTC, russhy wrote:
> On Wednesday, 10 November 2021 at 06:47:32 UTC, forkit wrote:
>> btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache. So I really don't give a damn about allocations .. not one little bit ;-)
>

> Having the right mindset helps not make these mistakes in the future
>
> Changing habits is hard, make sure to train yourself to pick the right one, early if possible

Umm.. you kinda missed the last part of my post...

..where I said..'Now if I were running a million processes across 1000's of servers, I probably would give a damn.'

C'mon... nothing in my code was 'unacceptable' in terms of speed or efficiency.

Making code transformations to improve speed and efficieny are important, but secondary. A newcomer cannot improve code that they do not understand ;-)

Picking understandable code first, IS right.

In any case, I say again, this thread is not about writing performance code per se, but about presenting code to new-comers, that they can make some sense of.

Taking some C code, and writing/presenting it in D (or vica-versa) in such a way that you can longer make any sense of it, is kinda futile.

I doubt the original op will ever come back to D, after seeing some of those examples that were provided ;-)

November 10, 2021
On Wednesday, 10 November 2021 at 23:05:06 UTC, H. S. Teoh wrote:
> On Wed, Nov 10, 2021 at 10:17:48PM +0000, russhy via Digitalmars-d-learn wrote:
>> On Wednesday, 10 November 2021 at 06:47:32 UTC, forkit wrote:
>> > btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache. So I really don't give a damn about allocations .. not one little bit ;-)
>> 
>> It's not a good mindset to have
>> 
>> Give room for the unexpected, don't burn all of your options right now
>> 
>> Having good foundation helps one to grow and scale faster than others
> [...]
>
> +1.
>
> Ironically, dmd itself is pretty care-free about allocating memory (in the name of compile speed -- after all, everybody has GBs of RAM to spare, but nobody wants to wait, right?). As a result, I cannot compile even simple programs on a low-memory system because the compiler runs out of memory and crashes before it can finish compiling.  What good is a super-fast compiler that cannot finish compiling before it uses too much memory?  Because of this, I have not dared to introduce D to my colleagues -- if they see what dmd does on the kind of low-memory embedded systems that we work on, they'd get such a bad impression of D they'll never ever want to hear about it again. :-/
>
>
> T

I still remember compiling code on my 286x86 ... talk about low memory..whoaaah.

These days, I have a 4GB ramdisk, put all the dmd/phobos..etc source code into that, and everything is read/compiled completely in memory, in seconds. The slowest part is copying the compilation back to disk, but even that happens so fast I don't even see it happen.

Worrying about an extra allocation here or there seems kinds trivial over here ;-)

November 10, 2021
On Wed, Nov 10, 2021 at 03:13:08PM -0800, Ali Çehreli via Digitalmars-d-learn wrote:
> On 11/10/21 3:05 PM, H. S. Teoh wrote:
> 
> > I cannot compile even simple programs on a low-memory system because the compiler runs out of memory
> 
> Did the -lowmem switch help in some cases?

On my (high-mem) home PC, it does help to reduce the memory footprint somewhat.  But unfortunately, not enough to make compilation work on the low-mem systems on all except the most trivial of programs.  So still no-go.


> Is -betterC any better? ;)
[...]

Have not tried. Maybe I'll give it a shot when I have some time. I'm not a fan, though. Using -betterC loses some of the key advantages D offers over C, and would probably not be incentive enough for my colleagues to consider adopting D. (We had tried C++ before and given up on it, so whatever is going to displace C in this space better offer a LOT more than C++ ever did. Simply being yet another variant of C isn't going to cut it.)


T

-- 
It is the quality rather than the quantity that matters. -- Lucius Annaeus Seneca
November 10, 2021
On Wed, Nov 10, 2021 at 11:39:40PM +0000, forkit via Digitalmars-d-learn wrote: [...]
> I still remember compiling code on my 286x86 ... talk about low memory..whoaaah.

That's nothing! ;-)

When I was a kid, I programmed a computer that had only 48K of RAM (that's 48 *kilo*bytes, not megabytes!).  The address space was 64K (16-bit), but beyond the 48K boundary was occupied by ROM which cannot be modified.


> These days, I have a 4GB ramdisk, put all the dmd/phobos..etc source code into that, and everything is read/compiled completely in memory, in seconds.  The slowest part is copying the compilation back to disk, but even that happens so fast I don't even see it happen.

In all likelihood, it isn't actually copying everything back to disk in that instant, but rather sitting in the HD cache while the controller slowly writes it to disk in the background. :-D  (Well, before that, in the OS cache.)


> Worrying about an extra allocation here or there seems kinds trivial over here ;-)

It depends on what you're doing. In the OP's example, yeah worrying about allocations is totally blowing things out of proportions.

But if you're in a time-constrained inner loop, you do *not* want to be allocating memory without a second thought, lest you provoke the ire of the GC and get a stop-the-world pause in the wrong moment.  E.g., when your radiotherapy dosage controller is just about to shut off the radiation beam, and the extra pause can mean death from overdose. :-P

Or y'know, the more important thing these days -- hundreds of your gamers will complain about jerkiness or lower framerates in their totally-important 60fps GPU-raytraced game. ;-)

Or, on a more serious note, if you're trying to solve a mathematically hard problem, needless allocations can mean the difference between getting the answer next week vs. the next century.  Sometimes these things *do* add up.


T

-- 
MSDOS = MicroSoft's Denial Of Service
November 11, 2021
On Thursday, 11 November 2021 at 00:11:07 UTC, H. S. Teoh wrote:
> On Wed, Nov 10, 2021 at 11:39:40PM +0000, forkit via Digitalmars-d-learn wrote: [...]
>> I still remember compiling code on my 286x86 ... talk about low memory..whoaaah.
>
> ...
> But if you're in a time-constrained inner loop, you do *not* want to be allocating memory without a second thought, lest you provoke the ire of the GC and get a stop-the-world pause in the wrong moment.  E.g., when your radiotherapy dosage controller is just about to shut off the radiation beam, and the extra pause can mean death from overdose. :-P
> ..


Silly me.. if only I had used v2.098.0 ... I might still be alive.

https://dlang.org/changelog/2.098.0.html#forkgc



November 11, 2021
On Thu, Nov 11, 2021 at 01:09:26AM +0000, forkit via Digitalmars-d-learn wrote:
> On Thursday, 11 November 2021 at 00:11:07 UTC, H. S. Teoh wrote:
> > On Wed, Nov 10, 2021 at 11:39:40PM +0000, forkit via Digitalmars-d-learn wrote: [...]
> > > I still remember compiling code on my 286x86 ... talk about low memory..whoaaah.
> > 
> > ...
> > But if you're in a time-constrained inner loop, you do *not* want to
> > be allocating memory without a second thought, lest you provoke the
> > ire of the GC and get a stop-the-world pause in the wrong moment.
> > E.g., when your radiotherapy dosage controller is just about to shut
> > off the radiation beam, and the extra pause can mean death from
> > overdose. :-P ..
> 
> 
> Silly me.. if only I had used v2.098.0 ... I might still be alive.
> 
> https://dlang.org/changelog/2.098.0.html#forkgc

😂


T

-- 
I am not young enough to know everything. -- Oscar Wilde