HNHacker News
TopNewBestAskShowJobs

GrantMoyer

2,084 karma · joined April 3, 2024

submissionscomments
GrantMoyer··on Most data centers refusing to say how much water, electricity they use
On a biological level, there'd be no problem providing a vegetarian diet for everyone. A healthful vegetarian diet is not hard to achieve, at least no harder than a healthful non-vegetarian diet.

From an infrastructure point of view, providing everyone vegetarian food sources overnight would not be possible, but that's not a realistic scenario. With a gradual transition, the transition would reduce overall resource use on basically all fronts, so there's no reason to expect extraordinary problems.

Of course, this is all theoretical unless people care enough to change their lifestyles.

GrantMoyer··on Most data centers refusing to say how much water, electricity they use
People need to eat, but they don't need to eat meat.
GrantMoyer··on Dutch governments builds alternative for Microsoft based on NixOS
I'm not familiar with patent legalese, but from my layman skimming of the patent application, I think you're right.

Instead, the patent would cover running object detection/classification ML models — optionally on remote servers — on screen and audio output and user input of specific applications (particularly videogames), without requiring cooperation from the application, to target ads based on what's happening in the application and to decide when to interrupt the application with an ad.

To hazard a guess: Microsoft or part of Microsoft is planning to include pervasive targeted advertising in the next Xbox console OS, including during gameplay of any game.

GrantMoyer··on How did AMD Ryzen get 50% faster in two years?
I'm not too familiar with the CPU world of performance measurement, but in GPU land, and I suspect for CPUs too, there are a slew of hardware "performance counters" which are registers that increment every time the event they measure happens.

So there could be a "instructions completed" counter and a "cycle" counter, and before starting the benchmark, you record the current value of both counters, then after the benchmark, record the final values, and compute the Instructions Per Cycle (IPC) as the difference in instructions completed over the difference in cycle count.

As for optimization, at a high level it's about minimizing the amount of time any part of the CPU is waiting for other parts of the CPU. The specifics require a lot of background knowledge about how modern CPUs work, more than can fit in a post, but if you're interested, topics to read about include:

### CPU cache hierarchy

CPUs store copies of data from RAM in smaller, faster memory physically closer to where the computation happens, so it's available more quickly. The CPU decides what values to store in the cache, and gives only limited control to the program, so an optimal program needs to be careful to not make the CPU make bad caching decisions (including for synchronizing the cache between multiple threads of execution).

### Instruction pipelining and out-of-order execution (a.k.a. "superscalar" execution)

Modern CPUs operate like an assembly line. A new instruction can start executing before the previous instruction(s) finishes. CPUs also have redundant hardware, so multiple instructions can be in progress at the same step of the pipeline. But there are limitations; sometimes the input to one instruction depends on the output of the previous instruction, so the whole pipeline stalls until the result is ready. An optimal program orders its operations to avoid these stalls as much as possible.

### Branch predicition

When the code to execute depends on the result of a computation, like in an `if` statement, we call it a branch. Branches can stall the pipeline, because the CPU doesn't know what instructions to execute next until the current result is ready. However, to mitigate this, modern CPUs predict which code-path will be taken when a branch is reached and begin executing the associated instructions immediately. If the prediction is right, the pipeline stall is avoided, but if it's wrong the pipeline state has to be restored to what it was before the wrong branch started executing, which is even more expensive than a stall. Usually, the CPU predicts branches correctly, so branch prediction is a net gain. Optimal programs need to understand how the CPU makes these predictions and make their branches as predictable as possible.

### Single Instruction, Multiple Data (SIMD)

Some programs do the same operations to each item of a set of data. CPUs have so-called SIMD instructions to accelerate this by, unsurprisingly, performing the same operation to multiple items at once. For example, they could add 4, 8, or even up to 64 pairs of numbers at once, depending on the instruction set and the range of the inputs. Suitable programs are optimized by arranging their inputs and operations so that SIMD instructions can be used — either directly or by being written in a way that a compiler can translate individual operations to SIMD operations.

GrantMoyer··on Dell admits consumers don't care about AI PCs
The idea is that NPUs are more power efficient for convolutional neural network operations. I don't know whether they actually are more power efficent, but it'd be wrong to dismiss them just because they don't unlock new capabilties or perform well for very large models. For smaller ML applications like blurring backgrounds, object detection, or OCR, they could be beneficial for battery life.
GrantMoyer··on When square pixels aren't square
Even with modern digital codecs and streaming, there's usually chroma subsampling[1], so the color channels may have non-square "pixels" even if overall pixels are nominally square. I most often see 4:2:0 subsampling, which still has square pixels, but at half resolution in each dimension. However 4:2:2 is also fairly common, and it has half resolution in only one dimension, so the pixels are 2:1. You'd have trouble getting a video decoding library to mess this up though.

[1]: https://en.wikipedia.org/wiki/Chroma_subsampling

GrantMoyer··on What is “literate programming”? (2024)
> This metalanguage must have some kind of constructs to describe unknown things, or things that are deliberately simplified in favor of exposition.

Perhaps you're thinking of mathematics.

If you have to be able to represent arbitrary abstract logical constructs, I don't think you can formalized the whole language ahead of time. I think the best you can do is allow for ad-hoc formalization of notation while trying to keep any newly introduced notation reasonably consitent with previously introduced notation.

GrantMoyer··on GitLab discovers widespread NPM supply chain attack
Linux supports per-process namespaces too, and has tools like firejail to use them for sandboxing, but nonetheless sandboxing is not widely used.
GrantMoyer··on I don't care how well your "AI" works
> if digital painting were solved not by a machine learning model, but human-readable code, it would be an even more bleak and cruel joke, isn't it?

On the contrary, I'm certain such a program would be filled with fascinating techniques, and I have no dread for the idea that humans aren't special.

GrantMoyer··on I don't care how well your "AI" works
I largely agree with this, but at the same time, I empathize with the FA's author. I think it's because LLMs feel categorically different from other technological leaps I've been exited about.

The recent results in LLMs and diffusion models are undeniably, incredibly impressive, even if they're not to the point of being universally useful for real work. However they fill me with a feeling of supreme dissapointment, because each is just this big black box we shoved an unreasonable amount of data into and now the black box is the best image processing/natural language processing system we've ever made, and depending on how you look at it, they're either so unimaginably complex that we'll never understand how they really work, or they're so brain-dead simple that there's nothing to really understand at all. It's like some cruel joke the universe decided to play on people who like to think hard and understand the systems around them.

GrantMoyer··on New OS aims to provide (some) compatibility with macOS
Test successful?
GrantMoyer··on Upcoming Rust language features for kernel development
Thanks for organizing for me my thoughts on why even a restricted modern subset of C++ is complicated.
GrantMoyer··on People regret buying Amazon smart displays after being bombarded with ads
Ditto. It's also significantly lighter weight than competing readers (at least when I bought mine), has physical buttons, has color models, and has really good battery life possibly because it runs a custom Linux instead of Android.
GrantMoyer··on Who needs Git when you have 1M context windows?
Like the author, I've also found myself wanting to recover an accidentally deleted file. Luckily, some git operations, like `git add` and `git stash`, store files in the repo, even if they're not ultimately committed. Eventually, those files will be garbage collected, but they can stick around for some time.

Git doesn't expose tools to easily search for these files, but I was able to recover the file I deleted by using libgit2 to enumerate all the blobs in the repo, search them for a known string, and dump the contents of matching blobs.

GrantMoyer··on Bad Apple but it's played inside Super Mario Bros
I'm not the author, but these video-in-game projects typically work with a few phases:

1. Get the game into a specific state by performing specific actions, moving to specific positions, performing specific inputs, etc. so that a portion of the game state in RAM happens to be an executable program.

2. Jump to that executable code such as by corrupting the return address in the stack with a buffer overflow

3. (optional) The program from 1 may be a simple "bootstrap" program which lets the player directly write a new, larger program using controller inputs then jumps to the new program.

4. The program reads the video and audio from the stream of controller inputs, decodes them, and displays them. The encoding is usually an ad-hoc scheme designed to take advantage of the available hardware. The stream of replayed inputs is computed directly from the media files.

GrantMoyer··on `std::flip`
There's a somewhat easier way to implement 2-argument-function flip in C++ than the blog post provides:

  #include <functional>
  constexpr auto flip(const auto& f) {
    return std::bind(f, std::placeholders::_2, std::placeholders::_1);
  }
The best I could get the fully general version is still pretty obtuse though:

  // std doesn't have a template version of placeholders::_1, _2, etc., so we need to
  // define our own. 
  template <int I> struct placeholder{};

  template<>
  template<int I>
  struct std::is_placeholder<placeholder<I>> : std::integral_constant<int, I> {};

  // flip must be an object so that the function type can be deduced without needing
  // to explicitly specify its parameters' types.
  template<typename F>
  struct flip {
    const F f;
    
    // operator() deduces the argument types when the flip object is called, but really
    // all we need to know is the number of arguments. 
    template<typename... Args>
    constexpr auto operator()(Args... args) {
      return bind_reversed(std::make_integer_sequence<int, sizeof...(Args)>{})(args...);
    }
    
    private:
    // a helper function is needed to deduce a sequence of integers so we can bind all
    // the placeholder values.
    template<int... Is>
    constexpr auto bind_reversed(std::integer_sequence<int, Is...>) {
      return std::bind(f, placeholder<sizeof...(Is) - Is>{}...);
    }
  };
GrantMoyer··on I ditched Docker for Podman
Docker Engine without Docker Desktop is available through winget as "Docker CLI"[1].

[1]: https://github.com/microsoft/winget-pkgs/tree/master/manifes...

GrantMoyer··on Rv, a new kind of Ruby management tool
Pyright catches an awful lot of dumb mistakes I make in Python.
GrantMoyer··on Wildthing – A model trained on role-reversed ChatGPT conversations
Is there any reason to explicitly train for role reversal? Can't you instead swap the input labels on any instruct tuned LLM? The model is trained on both sides of the chat log either way, right?
GrantMoyer··on A deep dive into Rust and C memory interoperability
Rust bindgen[1] will automatically generate native Rust stucts (and unions) from C headers where possible. Note that c_int, c_char, etc. are just aliases for the corresponding native Rust types.

However, not all C constructs have idomatic Rust equivalents. For example, bitfields don't exist in Rust, and unlike Rust enums, C enums can have any value of the underlying type. And for ABI reasons, it's very commom in C APIs to use a pointer to an opaque type paired with what are effectively accessor function and methods, so mapping them to accessors and methods on a "Handle" type in Rust often is the most idomatic Rust representation of the C interface.

[1]: https://github.com/rust-lang/rust-bindgen

GrantMoyer··on Vet is a safety net for the risky curl | bash pattern
Try Arch Linux. It hits all your points except maybe 5.

1. It symlinks redundant bin and lib directories to /usr/bin, and its packages don't install anything to /usr/local.

2. You can keep most config files in /etc or $XDG_CONFIG_HOME. Occasionally software doesn't follow the standards, but that's hardly the distro's fault.

3. Arch is bleeding edge

4. Arch repos are pretty big, plus thete's the AUR, plus packaging software yourself from source or binaries is practically trivial.

5. Security is not the highest priority over usability. You can configure SELinux and the like, but they're not on by default. See https://wiki.archlinux.org/title/Security.

6. There are few defaults to adhear to on Arch. Users are expected to customize.

GrantMoyer··on A media company demanded a license fee for an Open Graph image I used
There's no implied license because the news site that told them to use the image — through the OpenGraph protocol — is (supposedly) not the rights holder.
GrantMoyer··on Valve confirms credit card companies pressured it to delist certain adult games
I don't think that can explain why they're only targeting certain sub-categories of porn, and it's also contradictory to the public statements by Valve:

> We were recently notified that certain games on Steam may violate the rules and standards set forth by our payment processors and their related card networks and banks

Individual games violating "rules and standards" doesn't really fit with prohibiting a category because of high rates of fraud.

GrantMoyer··on Helix Editor 25.07
I'd love for Helix to implement a "Kakoune mode". I develop on Windows at work, where Kakoune is not ideal, so Helix seems like it'd be a perfect fit, except I can't get over the keybindings. Its keybinding philosophy encourages verbosity instead of Kakoune's terseness, which bothers me more than it probably should, and as far as I can tell its keymap configuration isn't yet powerful enough to emulate Kakoune well.

Vim's inconsistent keybinds and behavior are what pushed me to Kakoune — which I find has more consistent and elegant bindings and behavior — in the first place, and Helix feels like a step backwards on that front.

GrantMoyer··on Most ints are not floats
> On average the precision is equal. The mantissa just adds linear segments to a logarithmic curve.

Yes, exactly; the linear regions are needed to more evenly distribute precision, while the average precision remains the same. Alternatively, you can omit the mantissa, but use an exponent base much closer to 1 (perhaps 1 + 2⁻²³).

GrantMoyer··on Most ints are not floats
Without a mantissa, way too much precision is allocated to the near zero range and not enough to the "near infinity" range. Consider that without a mantissa, the second largest float is only half of the largest float. With a 23 bit mantissa, there are 2^23 floats from half the largest to the largest.
GrantMoyer··on Weird Expressions in Rust
Haskell has `bottom`[1] (see also [2]), which acts like Rust's `return` from a type checking perspective.

I wouldn't call using a uninhabited type for the type of a return expression theoretically inelegant. On the contrary, I find it quite pleasing.

[1]: https://wiki.haskell.org/Bottom

[2]: https://en.wikipedia.org/wiki/Bottom_type

GrantMoyer··on Fairphone 6 is switching to a new design that's even more sustainable
My phone is not the only device I use my ear buds with. Having to contantly attach and remove a usb-c adapter would be a complete pain in the ass. It's not just a matter of plugging it in — which would already be bad enough. I'd also need somewhere to store it, and I'd need to pack and unpack it each time. All that, or I could just buy a phone with a standard headphone port.
GrantMoyer··on New US visa rules will force foreign students to unlock social media profiles
Any law that allows a government to renounce people's citizenship for broad, vague reasons is a very, very bad law. Regardless of its intentions, it will be used as a tool to subvert the rights of citizens even outside the target group.
GrantMoyer··on WhatsApp introduces ads in its app
The problem with this is that once enough people are paying for an ad-free subscription, services reintroduce ads to the paid subscription, sometimes alongside the introduction of a new more expensive ad-free subscriotion.
Page 1 of 12Next →