Hacker News new | ask | show | jobs
by crawshaw 2311 days ago
This is an example of garbage collection being more CPU efficient than manual memory management.

It has limited application, but there is a more common variant: let process exit clean up the heap. You can use an efficient bump allocator for `malloc` and make `free` a no-op.

1 comments

There was also a variant of it with the hard drives: building Windows produced a huge amount of object files, so the trick used was to use a whole hard disk (or a partition) for that. Before the next rebuild, deleting all the files would took far more time than a "quick" reformatting of the whole hard disk, so the later was used.

(I am unable to find a link that talks about that, however).

In general, throwing away at once the set of the things together with the structures that maintain it is always faster than throwing away every item one by one while maintaining the consistency of the structures, in spite of the knowledge that all that is not needed at the end.

An example of arenas in C: "Fast Allocation and Deallocation of Memory Based on Object Lifetimes", Hanson, 1988:

ftp://ftp.cs.princeton.edu/techreports/1988/191.pdf

That's quite a clever solution, I doubt I would have thought of that!

Windows has always been my daily drivers, and I really do like it. But I wish deleting lots of files would be much, much faster. You've got time to make a cup of coffee if you need to delete a node_modules folder...

> I wish deleting lots of files would be much, much faster. You've got time to make a cup of coffee if you need to delete a node_modules folder

The example I gave was for the old times when people had much less RAM and the disks had to move physical heads to access different areas. Now with the SSDs you shouldn't be able to experience it that bad (at least when using lower level approaches). How do you start that action? Do you use GUI? Are the files "deleted" to the recycle bin? The fastest way is to do it is "low level" i.e. without moving the files to the recycle bin, and without some GUI that is in any way suboptimal (I have almost never used Windows Explorer so I don't know if it has some additional inefficiencies).

https://superuser.com/questions/19762/mass-deleting-files-in...

Even with an SSD, it's still bad. Much better than the several minutes it used to take with an HDD, but still annoying.

I just tried deleting a node_modules folder with 18,500 files in it, hosted on an NVMe drive. Deleting from Windows Explorer, it took 20s.

But then I tried `rmdir /s /q` from your SU link - 4s! I remember trying tricks like this back with an HDD, but don't remember it having such a dramatic impact.

>>> You've got time to make a cup of coffee if you need to delete a node_modules folder...

> Deleting from Windows Explorer, it took 20s.

> `rmdir /s /q` from your SU link - 4s

OK, so you saw that your scenarios could run much better, especially if Windows Explorer is avoided. But in Explorer, is that time you measured with deleting to the Recycle Bin or with the Shift Delete (which deletes irreversibly but can be faster)?

Additionally, I'd guess you don't have to wait at all (i.e. you can reduce it to 0 seconds) if you first rename the folder and than start deleting that renamed one and let it doing that in the background while continuing with your work -- e.g. if you want to create the new content in the original location it's immediately free after the rename, and the rename is practically immediate.

I pretty much exclusively use SHIFT-DEL (which has once or twice resulted in bad times!).

I didn't think about renaming then deleting - that's quite a nice workaround!

What I have noticed is that the CLI commands like rm -rf <dir> are orders of magnitude faster than the file explorer on linux. When I want to remove and then copy 500 .wav files for my anki deck it takes a minute or longer in the file explorer. With rm -rf media.collection/ && cp -rf <dir> media.collection/ it doesn't even take a second.