4,901 karma · joined Sep 13, 2020 (6y ago) · 1,641 submissions
comment 4y ago · link · parent
1. Hospital of the Transfiguration: <https://www.goodreads.com/book/show/251632.Hospital_of_the_T...>
2. Highcastle: A Remembrance: <https://www.goodreads.com/book/show/251630.Highcastle>
comment 4y ago · link · parent
comment 4y ago · link · parent
Also, I can never recommend Computer Systems: A Programmer's Perspective[1] enough. (Also features a rare mistakes in an exercise or two, but that's detail.)
And for network protocols, Comer's Internetworking with TCP/IP[3] was just great (you only need volume 1). I've read Stevens' books on socket and IPC programming in Unix, but didn't like them, so I also stayed away from TCP/IP Illustrated, but others have different opinions.
[1]: <https://www-cs-faculty.stanford.edu/~knuth/taocp.html>
[2]: <https://www.csapp.cs.cmu.edu/>
[3]: <https://www.pearson.com/us/higher-education/program/Comer-In...>
comment 4y ago · link · parent
comment 4y ago · link · parent
[1]: <https://plummerssoftwarellc.github.io/PrimeView/report?id=rb...>
comment 4y ago · link · parent
Saying they are "responsible" for those things is like saying that a river is responsible for flowing or the Earth is responsible for rotating.
comment 4y ago · link · parent
comment 4y ago · link · parent
Another non-functional application of tail call elimination is finite state machines. Writing them as functions calling the next state in tail call position is very elegant, legible and efficient.
comment 5y ago · link · parent
comment 5y ago · link · parent
That's true for copying generational garbage collectors. You only need to copy the live stuff and forget everything else. But in e.g. a mark-sweep collector, sweeping dead stuff takes time. In particular, e.g. Chromium's Oilpan can take a long time in the sweeping phase, when there are lot of dead objects.
But when there are a lot of microallocations, you also have a lot of live objects, which could otherwise be just a single object in the case of e.g. big arrays.
>> Another reason is eliminating unnecessary pointer indirection, which helps make sure that instead of loading data with two MOVs from memory polluting the cache, you need only one.
> Uh, that is locality, what I started with, no?
Hmm, seems I highlighted the wrong aspect. It's not just locality, but also size of the data you're dealing with. Those pointers take space. Another aspect of it is that arrays of unboxed elements have more predictable access patterns. Iterating over an array of unboxed elements is friendly to cache prefetching. CPUs recognize this (linear) pattern. With boxed elements and a compacting garbage collector locality may be fine, i.e. elements of the array may be close in memory, but the order in which you fetch elements is pretty random. When the cumulative size of the elements of the array is significantly larger than 64 bytes (the usual size of a cache line), then you're going to be prefetching the wrong regions of the array. There are situations where the order is going to be right, because e.g. the elements were created in the same order in which they are in the array, but that will be destroyed after some sorting, filtering or whatever.
comment 5y ago · link · parent
Spacial locality is one reason. Another very important reason is not generating unnecessary garbage. If you have a lot of microallocations, then your program is going to be slow regardless of you using manual memory management, RAII or a tracing GC. There is just a lot more stuff to do. With manual memory management, you're just going to call free() a lot (using big forward linked lists and freeing them with a function iterating over them, calling free() on each node? yikes). With RAII you're going to spend a lot of time in destructors due to an avalanche of objects freeing the objects they own (structs holding unique_ptr/shared_ptr to structs holding unique_ptr/shared_ptr to...? std::vector<std::string>/std::vector<std::unique_ptr>? these are all antipatterns when it comes to performance). With GC, you're going to have long GC pauses, because the GC needs to traverse a bigger graph of pointers (deep/broad trees of heap allocated objects? arrays of boxed objects? yikes).
Another reason is eliminating unnecessary pointer indirection, which helps make sure that instead of loading data with two MOVs from memory polluting the cache, you need only one.
For my current project, I use arenas to opt-out of RAII and have just a couple points in my project where memory is freed, instantly in one go. Needless to say, I don't use arrays of boxed elements. It's working great for me. Not only is it faster, but also simpler to understand and I don't need to fight with the borrow-checker as much as in normal (RAII) Rust, because my objects are grouped into longer lifetimes, so I don't need to think about separate lifetimes for every distinct little object.
That said, I'm spending some time gathering ideas for a toy language I'd design for myself to write an OS from the kernel up to userspace in, and I'm leaning towards a GC-based design that relies a lot on value types. One way or another, allocating a lot of little objects is stupid, because in every scenario it makes your program slower and, code quality-wise, at best it doesn't make a difference, but a lot of times it makes your code harder to reason about, because now a lot of things are remote to the place in code you're thinking about at any given time.
comment 5y ago · link · parent
comment 5y ago · link · parent
comment 5y ago · link · parent
To be clear, I do agree that a lot of cases of addiction will start with emotional problems getting people into prolonged consumption. However, emotional problems can also get people into obsessive running, yoga or whatever. But after getting their mind straight people generally don't need to be careful and abstain from running due to risk of a relapse of obsessive running --- contrast this with drugs, most prominently alcohol. Risk of relapse only happens with drugs, because it seems to my layman mind that it's not the emotional problems that get people addicted, but substance abuse. Emotional problems get people into substance abuse, but it's the substance that creates addiction, not the emotional problems, because see example with running.
And there are other triggers that get people into irresponsible consumption (societal expectations, such as in military[1]) that aren't emotional problems. They nonetheless often end in addiction, because of what the substance is doing to people's brains.
[1]: I'm talking about what I've heard from my father from Soviet era military about nicotine. I don't know what it looks like now/in other countries.
comment 5y ago · link · parent