News for hackers. Stuff that matters.
Re:fs.promises.readFile is 40% slower than fs.readFile by boring_twenties on Wednesday March 03, 2021 @08:54PM (#26337628)
I've posted about this before, but I know someone whose coworkers actually tried to defend themselves with "not leaking memory wasn't in the requirements," in a meeting with several managers, the subject of which was the memory leak.
Re:fs.promises.readFile is 40% slower than fs.readFile by josephg on Wednesday March 03, 2021 @09:43PM (#26337981)
I don't know whether its true but there's an old story of engineers a few decades ago working on the guidance system for a missile.

The programmers didn't bother to free() any of their memory - instead they just calculated the maximum amount of RAM their program could consume while the rocket was in the air, doubled it, then installed that much ram in the rockets.

Re:fs.promises.readFile is 40% slower than fs.readFile by fomine3 on Wednesday March 03, 2021 @09:47PM (#26338002)
Re:fs.promises.readFile is 40% slower than fs.readFile by boring_twenties on Wednesday March 03, 2021 @09:57PM (#26338078)
> the ultimate in garbage collection is performed without programmer intervention.

The author owes me a new keyboard.

Re:fs.promises.readFile is 40% slower than fs.readFile by hjek on Thursday March 04, 2021 @05:21AM (#26340731)
Thanks for the link.

Am I the only one who is terrified by reading an "amusing story" about "on-board software for a missile"? The amusement sort of requires us to completely ignore the individuals being blown to pieces.

Re:fs.promises.readFile is 40% slower than fs.readFile by tomgp on Thursday March 04, 2021 @05:42AM (#26340858)
I mean writing software for missiles kind of requires that mind set anyway
Re:fs.promises.readFile is 40% slower than fs.readFile by coldtea on Thursday March 04, 2021 @02:52AM (#26339831)
That's normal, as the rockets don't run an OS, run a specific , very explicitly defined, embedded program, with known states.

It's not going to malloc randomly...

In fact, it's common in real time applications to pre-allocate everything you need at the start of the program or use static memory, and never allocate afterwards.

Re:fs.promises.readFile is 40% slower than fs.readFile by capableweb on Thursday March 04, 2021 @05:09AM (#26340660)
I think the ultimate fact here is that you have a specific runtime period. Once the missile has reached its destination, you have zero memory and the runtime disappears together with the missile.
Re:fs.promises.readFile is 40% slower than fs.readFile by junon on Thursday March 04, 2021 @08:20AM (#26341956)
The ultimate free().
Re:fs.promises.readFile is 40% slower than fs.readFile by panda88888 on Friday March 05, 2021 @01:27AM (#26353508)
A literal destructor.
Re:fs.promises.readFile is 40% slower than fs.readFile by junon on Friday March 05, 2021 @04:00AM (#26354588)
Ooh that's better.
Re:fs.promises.readFile is 40% slower than fs.readFile by boring_twenties on Wednesday March 03, 2021 @09:55PM (#26338054)
Sounds funny, but is it actually unreasonable?

Presumably, the RAM was a rounding error in the total budget.

And this move eliminated an entire class of bugs (use after free).

edit: And, you don't have to worry about memory fragmentation, or how long free() might take in the worst case.

Re:fs.promises.readFile is 40% slower than fs.readFile by gizmo686 on Wednesday March 03, 2021 @10:21PM (#26338221)
When the European space agency designed the Ariane 4 rocket allocated 16 bits to some variable relating to its horizontal velocity. This variable was only used during the first minute of flight, and engineers computed that it could not possibly overflow given the launch profile Ariane 4 used. Because of this and limited processing power, engineers omitted an overflow check. This worked fine, and Ariane 4 would go on to launch succesfully 113/116 times (97%).

In 1996, Ariane 4's successor, Ariane 5, took its maiden voyage to carry the Cluster constellation into orbit, when this happened https://www.youtube.com/watch?v=gp_D8r-2hwk&t=54s

Ariane 5 used a different launch profile. The impossible was now possible and the 16 bit value overflowed. The inertial reference system failed, along with its backup (which was running the same code), causing the rocket to receive wrong data.

Re:fs.promises.readFile is 40% slower than fs.readFile by stonogo on Wednesday March 03, 2021 @10:26PM (#26338250)
Sounds like more of a warning against blindly copy-pasting code across projects than anything against the Ariane 4 design.
Re:fs.promises.readFile is 40% slower than fs.readFile by cutemonster on Thursday March 04, 2021 @12:50PM (#26345541)
Yes I agree.

At the same time, having added big uppercase warnings in the Ariane 4 source code and architecture docs, might have prevented this.

So, important, in safety critical code, to assume that others might blindly copy paste in bad ways -- and then try to warn them, although you might not be there any longer

Re:fs.promises.readFile is 40% slower than fs.readFile by Karunamon on Thursday March 04, 2021 @01:13AM (#26339224)
This sounds distressingly similar to the Therac-25 failures. A radiotherapy machine who's software was (blindly?) copy-pasted from a previous version of the system which had hardware interlocks to prevent unsafe configurations of the radiation emitter.

The new one did not have these interlocks, instead doing everything in software. The result of this was a few people being fatally irradiated when a certain race condition was triggered.

Re:fs.promises.readFile is 40% slower than fs.readFile by a_imho on Thursday March 04, 2021 @05:29AM (#26340780)
I know the relevant xkcd, but it is always Ariane, Therac and Mars Climate Orbiter.
Re:fs.promises.readFile is 40% slower than fs.readFile by zucker42 on Wednesday March 03, 2021 @10:21PM (#26338218)
I guess the problem is if their calculations are wrong and they are actually allocating more memory than expected.

I think a better approach (and one which NASA uses from what I've read) is to only use static memory.

Re:fs.promises.readFile is 40% slower than fs.readFile by kdtsh on Wednesday March 03, 2021 @09:59PM (#26338092)
Not at all unreasonable. You could very rightly consider any other arrangement ‘overengineered’
Re:fs.promises.readFile is 40% slower than fs.readFile by eternalban on Wednesday March 03, 2021 @10:09PM (#26338151)
Eminently reasonable: dispensing with memory management (allocate/gc) for an embedded real-time missile guidance system. It may have even had static memory layout which likely further improves performance.
Re:fs.promises.readFile is 40% slower than fs.readFile by willbudd on Wednesday March 03, 2021 @10:18PM (#26338204)
I'd be inclined not to use the heap at all though in that case. Just preallocate static arrays in each location.
Re:fs.promises.readFile is 40% slower than fs.readFile by brmgb on Thursday March 04, 2021 @01:23PM (#26346094)
More common than you think and a good way to do it. In a hard-real time environment where you need strong guaranties provably overshooting is a sane strategy. Freeing is not free. Missiles are extreme because they never will be reused but you can do the same at the process level. You just give the process more than it will need during its lifetime and don't bother with memory management.