frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Everything old is new again: memory optimization

https://nibblestew.blogspot.com/2026/03/everything-old-is-new-again-memory.html
48•ibobev•3d ago

Comments

est•1h ago
I think py version can be shortened as:

from collections import Counter

stats = Counter(x.strip() for l in open(sys.argv[1]) for x in l)

voidUpdate•1h ago
Would that decrease memory usage though?
griffindor•1h ago
Nice!

> Peak memory consumption is 1.3 MB. At this point you might want to stop reading and make a guess on how much memory a native code version of the same functionality would use.

I wish I knew the input size when attempting to estimate, but I suppose part of the challenge is also estimating the runtime's startup memory usage too.

> Compute the result into a hash table whose keys are string views, not strings

If the file is mmap'd, and the string view points into that, presumably decent performance depends on the page cache having those strings in RAM. Is that included in the memory usage figures?

Nonetheless, it's a nice optimization that the kernel chooses which hash table keys to keep hot.

The other perspective on this is that we sought out languages like Python/Ruby because the development cost was high, relative to the hardware. Hardware is now more expensive, but development costs are cheaper too.

The take away: expect more push towards efficiency!

pjc50•42m ago
>> Peak memory consumption is 1.3 MB. At this point you might want to stop reading and make a guess on how much memory a native code version of the same functionality would use.

At this point I'd make two observations:

- how big is the text file? I bet it's a megabyte, isn't it? Because the "naive" way to do it is to read the whole thing into memory.

- all these numbers are way too small to make meaningful distinctions. Come back when you have a gigabyte. It gets more interesting when the file doesn't fit into RAM at all.

The state of the art here is : https://nee.lv/2021/02/28/How-I-cut-GTA-Online-loading-times... , wherein our hero finds the terrible combination of putting the whole file in a single string and then running strlen() on it for every character.

dgb23•5m ago
> all these numbers are way too small to make meaningful distinctions. Come back when you have a gigabyte.

I have to disagree. Bad performance is often a result of a death of a thousands cuts. This function might be one among countless similarly inefficient library calls, programs and so on.

biorach•1h ago
"copyright infringement factories"
maipen•3m ago
Tells you right away where this is coming from.
tzot•45m ago
Well, we can use memoryview for the dict generation avoiding creation of string objects until the time for the output:

    import re, operator
    def count_words(filename):
        with open(filename, 'rb') as fp:
            data= memoryview(fp.read())
        word_counts= {}
        for match in re.finditer(br'\S+', data):
            word= data[match.start(): match.end()]
            try:
                word_counts[word]+= 1
            except KeyError:
                word_counts[word]= 1
        word_counts= sorted(word_counts.items(), key=operator.itemgetter(1), reverse=True)
        for word, count in word_counts:
            print(word.tobytes().decode(), count)
We could also use `mmap.mmap`.
fix4fun•37m ago
Digression: Nowadays when RAM is expensive good old zram is gaining popularity ;) Try to check on trends.google.com . Since 2025-09 search for it doubled ;)
canpan•22m ago
String views were a solid addition to C++. Still underutilized. It does not matter which language you are using when you make thousands of tiny memory allocations during parsing. https://en.cppreference.com/w/cpp/string/basic_string_view.h...
gostsamo•9m ago
> how much memory a native code version of the same functionality would use.

native to what? how c++ is more native than python?

Hold on to Your Hardware

https://xn--gckvb8fzb.com/hold-on-to-your-hardware/
65•LucidLynx•1h ago•28 comments

A Faster Alternative to Jq

https://micahkepe.com/blog/jsongrep/
147•pistolario•4h ago•75 comments

Should QA Exist

https://www.rubick.com/should-qa-exist/
18•PretzelFisch•49m ago•24 comments

Schedule tasks on the web

https://code.claude.com/docs/en/web-scheduled-tasks
155•iBelieve•6h ago•115 comments

The European AllSky7 fireball network

https://www.allsky7.net/#archive
61•marklit•4h ago•6 comments

Apple discontinues the Mac Pro

https://9to5mac.com/2026/03/26/apple-discontinues-the-mac-pro/
399•bentocorp•14h ago•314 comments

Why so many control rooms were seafoam green (2025)

https://bethmathews.substack.com/p/why-so-many-control-rooms-were-seafoam
831•Amorymeltzer•1d ago•160 comments

Everything old is new again: memory optimization

https://nibblestew.blogspot.com/2026/03/everything-old-is-new-again-memory.html
48•ibobev•3d ago•11 comments

Show HN: I put an AI agent on a $7/month VPS with IRC as its transport layer

https://georgelarson.me/writing/2026-03-23-nullclaw-doorman/
260•j0rg3•12h ago•75 comments

Local Bernstein theory, and lower bounds for Lebesgue constants

https://terrytao.wordpress.com/2026/03/23/local-bernstein-theory-and-lower-bounds-for-lebesgue-co...
3•jjgreen•3d ago•0 comments

QRV Operating System: QNX on RISC-V

https://r-tty.blogspot.com/2026/03/qrv-operating-system-first-publication.html
13•chrsw•4d ago•3 comments

$500 GPU outperforms Claude Sonnet on coding benchmarks

https://github.com/itigges22/ATLAS
290•yogthos•17h ago•157 comments

The Legibility of Serif and Sans Serif Typefaces (2022)

https://library.oapen.org//handle/20.500.12657/53344
50•the-mitr•3d ago•15 comments

DOOM Over DNS

https://github.com/resumex/doom-over-dns
295•Venn1•3d ago•84 comments

We rewrote JSONata with AI in a day, saved $500k/year

https://www.reco.ai/blog/we-rewrote-jsonata-with-ai
178•cjlm•12h ago•155 comments

Whistler: Live eBPF Programming from the Common Lisp REPL

https://atgreen.github.io/repl-yell/posts/whistler/
102•varjag•3d ago•6 comments

My minute-by-minute response to the LiteLLM malware attack

https://futuresearch.ai/blog/litellm-attack-transcript/
378•Fibonar•19h ago•145 comments

Show HN: Minimalist library to generate SVG views of scientific data

https://github.com/alefore/mini_svg/
30•afc•3d ago•2 comments

Running Tesla Model 3's computer on my desk using parts from crashed cars

https://bugs.xdavidhu.me/tesla/2026/03/23/running-tesla-model-3s-computer-on-my-desk-using-parts-...
899•driesdep•1d ago•309 comments

HyperAgents: Self-referential self-improving agents

https://github.com/facebookresearch/hyperagents
190•andyg_blog•2d ago•67 comments

Generators in Lone Lisp

https://www.matheusmoreira.com/articles/generators-in-lone-lisp
41•matheusmoreira•3d ago•8 comments

Anthropic Subprocessor Changes

https://trust.anthropic.com
82•tencentshill•13h ago•40 comments

Agent-to-agent pair programming

https://axeldelafosse.com/blog/agent-to-agent-pair-programming
78•axldelafosse•9h ago•25 comments

We haven't seen the worst of what gambling and prediction markets will do

https://www.derekthompson.org/p/we-havent-seen-the-worst-of-what
752•mmcclure•15h ago•527 comments

Chroma Context-1: Training a Self-Editing Search Agent

https://www.trychroma.com/research/context-1
47•philip1209•15h ago•3 comments

OpenTelemetry profiles enters public alpha

https://opentelemetry.io/blog/2026/profiles-alpha/
169•tanelpoder•19h ago•26 comments

Using FireWire on a Raspberry Pi

https://www.jeffgeerling.com/blog/2026/firewire-on-a-raspberry-pi/
88•jandeboevrie•14h ago•43 comments

Show HN: Fio: 3D World editor/game engine – inspired by Radiant and Hammer

https://github.com/ViciousSquid/Fio
73•vicioussquid•14h ago•6 comments

Chicago artist creates tourism posters for city's neighborhoods

https://www.chicagotribune.com/2026/03/25/chicago-neighborhood-posters/
95•NaOH•11h ago•45 comments

John Bradley, author of xv, has died

https://voxday.net/2026/03/25/rip-john-bradley/
272•linsomniac•16h ago•81 comments