Live data from Hacker News

When static makes your C code 10 times faster

mazzo.li

111–113 of 113 posts

Re: When static makes your C code 10 times faster

#112

Earlier quoted context omitted.

There is one common situation where not using mutable globals is a recipe for complexity and a serious code smell. That case is when your internal structures directly control the physical resources of the machine. There is no amount of window dressing that can make these anything but global structures because that is what they literally are. That gets hidden a bit if you delegate resource management to the OS but you…

Maaaaybe. There are definitely resources which are globally unique. But that does not necessarily follow that access should also be global. Rust has some elegant patterns when working with embedded devices. For example GPIO pins could totally be stateful globals. But instead their passed around as types and Rust’s type system + borrow checker ensure correctness. It’s pretty neat. I’ll assume you’re right for database…

Rust struggles with software where most of the address space is used for DMA, like many database engines, because it requires ownership and mutability to be observable at compile-time. Also, DMA often does not respect object boundaries as a compiler sees it because DMA does not understand objects.

In modern C++ it is straightforward to write wrappers in the style of unique_ptr that safely hide the DMA and life cycle mechanics, which means the average dev using them doesn’t need to know how it works, but someone has to write that code and it is necessarily global heavy because it references physical devices that have their own behavior in your address space. Under the hood, if a physical device is stomping on address space your code accesses, you need a way to both detect that an object is effectively owned by a particular DMA engine before touching it and immediately de-schedule the thread of execution until such a time as there is no concurrent DMA operation that might conflict with the code execution. This happens within a single thread, so no blocking or OS context switching.

A big part of database kernel internals is coordination and management of physical resources, which are global by nature.

Re: When static makes your C code 10 times faster

#113

Earlier quoted context omitted.

You shouldn't assume you're running on the performance cores. Not everyone is writing an app, and even if you are, most of your code will be better off on the efficiency cores.

If you're not concerned enough about performance to run on the performance cores, then why worry about...performance?

They aren't always available because you can't always get what you ask for.
Post reply on HN