frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Tailscale state file encryption no longer enabled by default

https://tailscale.com/changelog
72•traceroute66•1h ago•44 comments

Sugar industry influenced researchers and blamed fat for CVD (2016)

https://www.ucsf.edu/news/2016/09/404081/sugar-papers-reveal-industry-role-shifting-national-hear...
513•aldarion•7h ago•329 comments

Shipmap.org

https://www.shipmap.org/
345•surprisetalk•6h ago•58 comments

NPM to implement staged publishing after turbulent shift off classic tokens

https://socket.dev/blog/npm-to-implement-staged-publishing
89•feross•3h ago•11 comments

US will ban Wall Street investors from buying single-family homes

https://www.reuters.com/world/us/us-will-ban-large-institutional-investors-buying-single-family-h...
289•kpw94•2h ago•253 comments

Eat Real Food

https://realfood.gov
242•atestu•4h ago•459 comments

LaTeX Coffee Stains (2021) [pdf]

https://ctan.math.illinois.edu/graphics/pgf/contrib/coffeestains/coffeestains-en.pdf
250•zahrevsky•6h ago•53 comments

Health care data breach affects over 600k patients, Illinois agency says

https://www.nprillinois.org/illinois/2026-01-06/health-care-data-breach-affects-600-000-patients-...
114•toomuchtodo•5h ago•43 comments

Native Amiga Filesystems on macOS / Linux / Windows with FUSE

https://github.com/reinauer/amifuse
46•doener•4d ago•8 comments

We found cryptography bugs in the elliptic library using Wycheproof

https://blog.trailofbits.com/2025/11/18/we-found-cryptography-bugs-in-the-elliptic-library-using-...
17•crescit_eundo•6d ago•2 comments

Creators of Tailwind laid off 75% of their engineering team

https://github.com/tailwindlabs/tailwindcss.com/pull/2388
729•kevlened•5h ago•458 comments

Claude Code Emergent Behavior: When Skills Combine

https://vibeandscribe.xyz/posts/2025-01-07-emergent-behavior.html
21•ryanthedev•1h ago•7 comments

A4 Paper Stories

https://susam.net/a4-paper-stories.html
254•blenderob•8h ago•127 comments

Many hells of WebDAV

https://candid.dev/blog/many-hells-of-webdav
92•candiddevmike•5h ago•54 comments

Claude Code CLI Broken

https://github.com/anthropics/claude-code/issues/16673
66•sneilan1•1h ago•61 comments

Building voice agents with Nvidia open models

https://www.daily.co/blog/building-voice-agents-with-nvidia-open-models/
55•kwindla•5h ago•2 comments

A glimpse into V8 development for RISC-V

https://riseproject.dev/2025/12/09/a-glimpse-into-v8-development-for-risc-v/
15•floitsch•16h ago•2 comments

LMArena is a cancer on AI

https://surgehq.ai/blog/lmarena-is-a-plague-on-ai
9•jumploops•16h ago•1 comments

Meditation as Wakeful Relaxation: Unclenching Smooth Muscle

https://psychotechnology.substack.com/p/meditation-as-wakeful-relaxation
115•surprisetalk•6h ago•77 comments

What *is* code? (2015)

https://www.bloomberg.com/graphics/2015-paul-ford-what-is-code/
95•bblcla•5d ago•36 comments

ChatGPT Health

https://openai.com/index/introducing-chatgpt-health/
66•saikatsg•2h ago•74 comments

Notion AI: Unpatched data exfiltration

https://www.promptarmor.com/resources/notion-ai-unpatched-data-exfiltration
11•takira•1h ago•1 comments

So you wanna de-bog yourself (2024)

https://www.experimental-history.com/p/so-you-wanna-de-bog-yourself
3•calvinfo•23m ago•1 comments

Polymarket refuses to pay bets that US would 'invade' Venezuela

https://www.ft.com/content/985ae542-1ab4-491e-8e6e-b30f6a3ab666
192•petethomas•19h ago•179 comments

Optery (YC W22) Hiring a CISO and Web Scraping Engineers (Node) (US and Latam)

https://www.optery.com/careers/
1•beyondd•9h ago

Show HN: An LLM response cache that's aware of dynamic data

https://blog.butter.dev/on-automatic-template-induction-for-response-caching
3•raymondtana•35m ago•0 comments

The Target forensics lab (2024)

https://thehorizonsun.com/features/2024/04/11/the-target-forensics-lab/
61•jeromechoo•5h ago•97 comments

A tab hoarder's journey to sanity

https://twitter.com/borisandcrispin/status/2008709479068794989
63•borisandcrispin•3h ago•70 comments

Everything You Need to Know About Email Encryption in 2026

https://soatok.blog/2026/01/04/everything-you-need-to-know-about-email-encryption-in-2026/
9•some_furry•2d ago•2 comments

Show HN: I built a "Do not disturb" Device for my home office

https://apoorv.page/blogs/over-engineered-dnd
63•quacky_batak•4d ago•31 comments
Open in hackernews

Swapping two blocks of memory inside a larger block, in constant memory

https://devblogs.microsoft.com/oldnewthing/20260101-00/?p=111955
46•paulmooreparks•5d ago

Comments

praptak•1d ago
I think this was discussed in Jon Bentley "programming pearls"?

Also in the same book it was mentioned that the disjoint cycles method (also mentioned in the article) was worse for paging/caching than the three reverses method.

ot•1d ago
That's probably true for small primitive types, but if your objects are expensive to move (like a large struct) it might be beneficial to minimize swaps.
praptak•1d ago
Yeah, it might be interesting to run some profiling of both algorithms and see how they perform dependent on the size of the blocks being swapped (which doesn't even have to be equal to the size of the object in the array).
taeric•1d ago
It is discussed in that book. Very fun read, all told. Highly recommended if folks find this sort of thing fun. I think I should thumb through it again. :D
jnellis•1d ago
Java chooses to use the cycle method mostly. They also reference Bentley.

https://github.com/openjdk/jdk/blob/f1e0e0c25ec62a543b9cbfab...

j4cobgarby•1d ago
You can also use the XOR trick, not sure what's faster though.
adrian_b•1d ago
The XOR trick was sometimes useful in the past, on weird CPUs that had non-equivalent registers and which also lacked register exchange instructions (the Intel/AMD CPUs have non-equivalent registers, but they have a register exchange instruction, so they do not need this trick).

The XOR trick is not useful on modern CPUs for swapping memory blocks, because on modern CPUs the slowest operations are the memory accesses and the XOR trick needs too many memory accesses.

For swapping memory, the fastest way needs 4 memory accesses: load X, load Y, store X where Y was, store Y where X was. Each "load" and "store" in this sequence may consist of multiple load or store instructions, if multiple registers are used as the intermediate buffer. Ideally, an intermediate register buffer matching the cache line size should be used, with accesses aligned to cache lines.

Hopefully, std::rotate is written in such a way that it is compiled into such a sequence of machine instructions.

Someone•1d ago
> with accesses aligned to cache lines.

You want that, but can be tricky because the from and to regions may have different alignment.

Also, the XOR trick introduces data dependencies. That slows down pipelined CPUs.

SkiFire13•1d ago
How does that work for swapping two blocks of memory with different sizes (which may require shifting the data inbetween)?
jhatax•1d ago
As a commenter noted as well, you can perform the swap using two std::rotate calls vs. three (less than 2N operations). This said, Raymond’s use of reverse is still most efficient at N operations (not considering paging/caching issues).
HarHarVeryFunny•1d ago
Isn't he also using 2N operations?

To swap B and D, with intervening C (i.e. B C D), what he his doing is individually reversing each of B C, and D (= total N swaps), then reversing the combined B' C' D' (= another N swaps).

TrainedMonkey•1d ago
Apparently the trick is two std::rotates : https://devblogs.microsoft.com/oldnewthing/20260101-00/?p=11...

As a side note, love how Raymond handled that, no fluff and straight to the point. Beginners mind and all that.

trjordan•1d ago
There's something about this that's unsatisfying to me. Like it's just a trivia trick.

My first read of this was "this seems impossible." You're asked to move bits around without any working space, because you're not allowed to allocate memory. I guess you could interpret this pedantically in C/C++ land and decide that they mean no additional usage of the heap, so there's other places (registers, stack, etc.) to store bits. The title is "in constant memory" so I guess I'm allowed some constant memory, which is vaguely at odds with "can you do this without allocating additional memory?" in the text.

But even with that constraint ... std::rotate allocates memory! It'll throw std::bad_alloc when it can't. It's not using it for the core algorithm (... which only puts values on the heap ... which I guess is not memory ...), but that function can 100% allocate new memory in the right conditions.

It's cool you can do this simply with a couple rotates, but it feels like a party trick.

SkiFire13•1d ago
> But even with that constraint ... std::rotate allocates memory! It'll throw std::bad_alloc when it can't.

This feels kinda crazy. Is there a reason why this is the case?

quuxplusone•20h ago
That's only for the parallel overload. The ordinary sequential overload doesn't allocate: the only three ordinary STL algorithms that allocate are stable_sort, stable_partition, and (ironically) inplace_merge.
HarHarVeryFunny•1d ago
No - std::rotate is just doing this with in-place swaps.

Say you have "A1 A2 B1" and want to rotate (swap) adjacent blocks A1-A2 and B1, where WLOG the smaller of these is B1, and A1 is same size as B1.

What you do is first swap B1 with A1 (putting B1 into it's final place).

B1 A2 A1

Now recurse to swap A2 and A1, giving the final result:

B1 A1 A2

Swapping same-size blocks (which is what this algorithm always chooses to do) is easy since you can just iterate though both swapping corresponding pairs of elements. Each block only gets moved once since it gets put into it's final place.

hacker_homie•1d ago
You are thinking of std::swap, std::rotate does throw bad_alloc
HarHarVeryFunny•1d ago
I see it says that it may throw bad_alloc, but it's not clear why, since the algorithm itself (e.g see "Possible implementation" below) can easily be done in-place.

https://en.cppreference.com/w/cpp/algorithm/rotate.html

I'm wondering if the bad_alloc might be because a single temporary element (of whatever type the iterators point to) is going to be needed to swap each pair of elements, or maybe to allow for an inefficient implementation that chose not to do it in-place?

taeric•1d ago
To be fair, it originates from a time when memory was tighter. Is discussed with some motivating text in Programming Pearls. I can't remember the context, but I think it was in a text editor. I can look it up, if folks want some of that context here.
osullivj•1d ago
Also useful for cache locality, a more recent trend. But I guess that's just another slighlty diff case of tight mem; this time in the cache rather than RAM generally.
HarHarVeryFunny•1d ago
I did something similar back in the day to support block-move for an editor running on a memory constrained 8-bit micro (BBC Micro). It had to be done in-place since there was no guarantee you'd have enough spare memory to use a temporary buffer, and also more efficient to move each byte once rather than twice (in/out of temp buffer).
wakawaka28•19h ago
The problem seems less arbitrary if the chunks being rotated are large enough. Implicit in the problem is that any method that would require additional memory to be allocated would probably require memory proportional to the sizes of stuff being swapped. That could be unmanageable.

As for whether std::rotate() uses allocations, I can't say without looking. But I know it could be implemented without allocations. Maybe it's optimal in practice to use extra space. I don't think a method involving reversal of items is generally going to be the fastest. It might be the only practical one in some cases or else better for other reasons.

HarHarVeryFunny•1d ago
Couldn't this be done in 2 rotates rather than 3 :

A B C D E

A C B D E -- after rotate B, C

A D C B E -- after rotate C-B, D

Complexity would seem to be the same as the reverse method, since every element in the original B-D range is getting moved twice.

cbsks•22h ago
On Linux, if the blocks are page aligned, you could use mremap(2) to swap blocks very efficiently without using any additional physical memory.
throwawayk7h•21h ago
This should also be possible with [XOR swap](https://en.wikipedia.org/wiki/XOR_swap_algorithm), though you need to do three passes.
notepad0x90•14h ago
I was anticipating a SIMD shuffle/permute instruction like vpermq, it won't allocate more ram-memory per-se.

Anyways, here is what google search AI gave me as an example of how that would work (I don't know this stuff well enough myself):

; Assume ymm0 contains [A, B, C, D] (Q0=A, Q1=B, Q2=C, Q3=D)

; The immediate 0xd8 (11011000 in binary) means:

; - Keep Q0 (index 0)

; - Swap Q1 (index 1) with Q2 (index 2) (110, 011 in binary for bits 1,2)

; - Keep Q3 (index 3)

vpermq ymm0, ymm0, 0xd8

; ymm0 now contains [A, C, B, D]