

Join the discussion
Write your take first — we'll ask for email only when you're ready to publish.
- Hacker News
- My eyes glazed over when I saw "recursively", and I had to re-read the last couple paragraphs again to grok it, and it's very cool.by ang_cire
- What is amazing is the amount of consideration given to an issue which would escape the majority of users. It is surprising how complex an apparently easy process turns out when considering certain special cases.by Aditya_0315
- I love the understated "some time ago" linking to a 2004 blog post. Raymond has been at this a long time :-)by rietta
- I love that 2004 sounds like "some time ago" to some people. Seems like yesterday to me.by SoftTalker
- > it’s more efficient because it reduces the amount of calls into the file system
OK, but isn't the kernel keeping the directory listing in the disk cache? Won't that prevent extra physical I/O if you do just read the directory twice?
If so, then in the second pass, it's all cache hits, and you're just paying the cost of calling into the file system. Hopefully that's pretty fast. But even if not, it's still absolutely dwarfed by the physical I/O required for the first pass. Windows XP era storage was spinning hard drives, not flash.
And if not, then I'm probably going to put my user icon coding task on the back burner and go ask the kernel team why a seemingly very common usage pattern isn't optimized.
(I realize he's not claiming the performance benefit was significant. I'm just trying to see it in the right perspective.)
by adrianmonk - less work is always cheaper. no matter what.by bombela
- It's somewhat odd that filesystems don't have a call to tell you how many files are in a folder.by ape4
- just have it count how many times del cmd runs successfully /sby conorcleary
- I feel like there would either be too many locks or too much contention on something like /var/log or /tmp if that API was ever exposed to userspace.by eventualcomp
- Either that call would have to do the same (i.e., walking the files and counting), or you'd need some additional metadata in the directory entry to store how many files there are, requiring additional storage accesses for adding and removing files. Adding to that that both FAT32 and NTFS are quite old and had to run on older hardware. Cycles and disk accesses are not free.
On top of that, how often is it necessary to efficiently know the number of files in a directory while at the same time not caring about the files enough to list or display them? This algorithm is a special case where you could use the count of using a bit simpler code that ultimately would have the same file system API calls (since you cannot tell the FS to give you file #37 from that directory, so you'd have to use FindNextFile 37 times anyway, just like the sampling algorithm).
by ygra - A couple of screenshots would've been useful for the post-millennial generations that never got to see the "beauty" (cough) of XP.by jasonvorhe
- I don't see how that's relevant? Article is about the RNG implementation, it doesn't matter what the profile pictures are.
- I thought it looked great :-/by CalRobert
- XP is Microsoft's prettiest OS by far.by Maken
- Here's a blog post from 2003 with beautiful pictures.
https://jakeludington.com/2003/12/17/create_your_own_windows...
- The times when people spent an extra brain cycle to avoid billions of second passes.by cgio
- This is a fun example of the cognitive switch you have to employ when first starting to program a computer. It's extremely easy for a human to pick at random one thing from a pile of things: you reach out your hand and grab it, maybe swirling them around on the table first to shuffle the order. For a computer, there's no direct analogy to that. They just can't do it. And the human process is nothing even slightly like the one the computer follows: we don't have to count the sets and iterate over them, or count the items and then generate a random number to pick the nth item, or risk picking a null item.by scrumper
- I think this article highlights more the importance of understanding system limits in the 1990s versus today. No-one would care to much today if the code review for this feature had “files.count()” or whatever in it, but in the mid 90s that would have been a huge performance red flag because a user would literally hear their hard drive clicking away and see the blinkenlights.by rhplus
- >Raymond has been involved in the evolution of Windows for more than 30 years. He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.by impoppy
- A true Microsoft drone to the end.
- That made me chuckle too. No utility, but I did find it interesting.by carrja99
- For those interested, here's the actual code Chen talks about: https://github.com/tongzx/nt5src/blob/daad8a087a4e75422ec96b...by EMIRELADERO
- I don't see how this is supposedly more efficient than the easier approach of listing all files and choosing a single random number in 1..nby Sopel
- Didn't know that NT5 source is available for the public. Why Microsoft does not ban/delete it on GitHub?by ycuser2
- Man, every post from Raymond Chen regarding Windows internals is like a little Xmas. I wonder whether he has to ask someone for permission before publishing this knowledge, though.by lyorig
- If you ask for permission on something like this the answer is always no.by fred_is_fred
- Isn't there a guy on youtube that spills tea about the internals of old windows systems? And I suspect their NDAs about XP expired years ago - I don't see much harm in sharing these herbivore algorithms. Very cute post tho.by petya415
- I also wonder what his thoughts on “modern Windows” areby alex_suzuki
- Easier for a guy like him to be forgiven than to ask permission.
Being tenured and one of the top engineers in your company with a very proven track record gives you quite a bit more freedom.
by Hydraulix989 - It's been many years since I talked to him, but he's an extremely by-the-book guy, so I'm sure he has a process for clearing everything he writes. His reputation does probably provide him a lot of leeway, though. He also has a queue of oldnewthing articles about a mile long and we could probably get years' worth of articles after his death if they let them run.by cloudfudge