HackerURLs

一次又一次被重新发现的经典。

同一个链接,相隔一年以上,一次又一次被人重新发现、再次冲上 Hacker News 首页。能经受住这种时间检验的,大多是值得一读再读的文章。每篇附中文标题,讨论最热的那些再加上中文导读和高赞评论翻译。

从名人堂开始
  • 4,700+篇经过时间检验的经典

Hall of fame

名人堂

在经典库里看全部精选

上首页次数最多、而且有中文导读的 30 篇。时间轴上每个黑点是一次上首页,空心点是一次没冲上去的投稿。

  1. 正在载入经典…

Archive

经典库

按第一次上首页的年份分布,点柱子筛选。

排序

    About

    这些经典是怎么挑出来的

    1. 01

      合并同一个链接

      读取 Hacker News 自 2006 年以来的全部链接投稿,把 http/https、www、跟踪参数等写法不同的同一篇文章合并成一条。

    2. 02

      只留经得起时间的

      同一链接至少两次拿到 50 分以上(约等于上首页),而且两次相隔一年以上;再由 AI 剔除状态页、产品首页和新闻事件。

    3. 03

      写导读、译评论

      上首页次数最多的 2,000 篇配上中文导读、"为什么经久不衰",并精选翻译 HN 高赞评论。导读由 AI 生成,可能有误。

    系统与基础设施justinmeiners.github.io编辑精选

    动手写一个自己的虚拟机

    Write Your Own Virtual Machine

    2次上首页
    2年跨度
    880累计得分
    119条评论

    2018 — 2020,它一次次回到首页

    黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。

    导读

    这是一篇用 C 语言从零实现一个 LC-3 虚拟机的教程:逐步讲解指令读取、分发、执行以及基础 I/O,最终得到一个可运行的小型 VM。LC-3 是精简的教学指令集,因此这篇教程篇幅不大,但覆盖了 VM 的核心机制。

    为什么经久不衰:它把“虚拟机”和“CPU 如何执行指令”从抽象概念变成可动手写出的代码,是理解解释器、编译器和计算机体系结构公认的入门经典。

    关键词 虚拟机LC-3C 语言计算机体系结构

    HN 评论精选

    用 computed goto 跳转表替代 switch 分发,可以把每条指令的分支次数从三次降到一次。

    我实现 VM 时最喜欢的技术之一是 computed goto。文章里用 switch 分发指令,每执行一条指令其实要跳三次:switch 跳到对应 case、break 到末尾、再跳回 while 循环顶部。改用跳转表加 goto 后,每条指令处理完直接跳到下一个位置,只剩一次分支。

    chrisaycock查看英文原文

    One of my favorite techniques for implementing VMs is the "computed goto": https://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables Consider this example for dispatching instructions from the article: while (running) { uint16_t op = mem_read(reg[R_PC]++) >> 12; switch (op) { case OP_ADD: {ADD, 6} break; case OP_AND: {AND, 7} break; case OP_NOT: {NOT, 7} break; case OP_BR: {BR, 7} break; ... } } That code has a lot of branching. The switch statement has to jump to the corresponding case, the break statement branches to the bottom, and then there is third branch to get back to the top of the while loop. Three branches just to hit one instruction. Now imagine we had written the above as: static void* dispatch_table[] = { &&OP_ADD, &&OP_AND, &&OP_NOT, &&OP_BR, ... }; #define DISPATCH() goto *dispatch_table[memory[reg[R_PC]++] >> 12] DISPATCH(); OP_ADD: {ADD, 6} DISPATCH(); OP_AND: {AND, 7} DISPATCH(); OP_NOT: {NOT, 7} DISPATCH(); OP_BR: {BR, 7} DISPATCH(); ... Now there is only one branch per instruction. The handler for each instruction directly jumps to the next location via the goto. There is no need to be in an explicit loop because the interpreter runs until it hits a halting instruction. Many VMs now use this technique, including the canonical Ruby and Python interpreters.

    大 switch 在 -O3 下可以很快,但把 VM 拆成过多模块会严重拖慢主循环;作者并发实现反而慢于单线程。

    我曾用 Ada 实现过一个 VM,只用一个大的 switch,大量基准测试显示 -O3 下速度极快。但前提是极少使用 package;与 Ada 社区的建议相反,把实现拆成多个 package 会严重拖慢主循环(我用的 gcc 对 Ada 不支持全程序优化)。另外我的绿色线程无论怎么尝试都比单线程慢。项目最终废弃了,因为配套汇编器是用 Racket 拼凑的,后来我自己也理不清了。

    jonathanstrange查看英文原文

    I once implemented a VM in Ada and just used a large switch. I extensively benchmarked it and it was blazingly fast at -O3. However, it was only fast when I used packages very sparingly. In contrast to the usual advice given in the Ada community, splitting up the implementation into several packages slowed down the main loop tremendously. I suspect this wouldn't happen with whole-program optimization in C, but believe that the version of gcc I was using didn't support that for Ada. Also, my Green Threads were slower than a single thread, no matter which tricks I tried. It's an abandoned project now, since the accompanying assembler was hacked together in Racket and at some point I simply lost track of what was going on where :O

    Advent of Code 2019 的 VM 系列是零基础动手实现并应用 VM 的绝佳练习路径。

    去年玩 Advent of Code 时我被“骗”去写了一个 VM,它确实加深了我对编程的理解(比如怎样实现简单协程)。我本以为 AoC 全是算法和数据结构题,结果一半是在实现并使用一门虚构的汇编语言!难度曲线足够平缓,我没有编译器背景也做完了。2019 年的第 2、5、7、9 天写 VM,再用第 11、13、15、17、19、21、23、25 天的题去应用它。我最后爱上了这些 VM 题,还去做了 AoC 作者的其他类似挑战。

    ghj查看英文原文

    I was tricked into writing a VM while doing Advent of Code last year and it really deepened my understanding of programming (e.g., on how to implement simple coroutines). Advent of Code is supposed to be 25 daily programming puzzles leading up to christmas. I went in thinking they were going to be algo/datastructure tasks but half of them were actually about implementing and using a VM for a made up assembly language! The difficulty ramp was gradual enough that I did it with no background in compilers and it was lots of fun. If you want to experience it, in last year's version https://adventofcode.com/2019 you write the VM in Days 2, 5, 7, 9 then apply it to solving problems in Days 11, 13, 15, 17, 19, 21, 23, 25. I ended up loving the VM puzzles and ended up doing the AoC author's other challenges which have a similar theme: https://challenge.synacor.com/

    从逻辑门和晶体管自底向上搭建 CPU 与工具链完全可行,作者最终做出了能运行 Game of Life 的简易计算机。

    我曾从最简单的构件开始写过虚拟 CPU,强烈推荐这么做。从只包一个 bool 的 Wire 类和接收两个 Wire&、有一个 Update() 设置输出的 Transistor 类开始,我搭出了逻辑门、触发器、寄存器、多路复用器、计数器、ALU 和内存 bank;然后定义机器语言,连接 CPU,写加载器把机器码载入 ROM,再写汇编器来编写汇编;最后加上 VRAM 和异步总线,跑通了 Game of Life。它有 32 位指令,8KB 内存下大约 10kHz。

    cecilpl2查看英文原文

    I have written a virtual CPU from very simple building blocks and highly recommend doing it. I started with class Wire (which just wraps a bool) and class Transistor (which accepts two input Wire& and has an output Wire). It has an Update() function which sets the output state. From those I built up gates, then flipflops, registers, mux/demuxes, counters, an ALU, and memory banks. Then I wrote a machine language, connected the cpu together, wrote a loader to load machine language files into ROM, then an assembler to allow me to write assembly code. I then added VRAM, async buses, and wrote a working implementation of Game of Life. It has 32bit instructions and runs about 10kHz with 8KB of RAM.

    历次讨论

    同类还值得读

    1. TTY 揭秘(2008)

      The TTY demystified (2008)

      经典文章深入剖析了 Unix/Linux 中 TTY 子系统的工作原理,包括线路规程、终端驱动、信号与控制字符等机制。

      系统与基础设施上首页 11 次 · 2009–2025linusakesson.net编辑精选
    2. 为什么 GNU grep 这么快

      Why GNU grep is Fast

      FreeBSD 邮件列表上一篇广为流传的帖子,解释 GNU grep 为什么快:核心在于 Boyer-Moore 字符串搜索算法配合精心优化的内部循环和 I/O,让程序在搜索时“…

      系统与基础设施上首页 9 次 · 2010–2022lists.freebsd.org
    3. Xplain:为普通人讲解 X11

      Xplain – Explaining X11 for the rest of us

      《Xplain》是作者(HN 用户 Jasper_)写的一系列 X11 长文,用他在浏览器中重建的 X11 绘图模型做交互演示,讲解 X11 的绘图模型与窗口系统设计。

      系统与基础设施上首页 6 次 · 2013–2020magcius.github.io编辑精选
    4. 旋风教程:为 Linux 创建极小 ELF 可执行文件(1999)

      A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux (1999)

      breadbox 写于 1999 年的经典教程,主题是如何为 Linux 手工构造并裁剪出体积极小的 ELF 可执行文件。

      系统与基础设施上首页 6 次 · 2007–2025muppetlabs.com
    5. PostgreSQL 内部原理

      The internals of PostgreSQL

      《The Internals of PostgreSQL》是一本免费在线书籍,系统讲解 PostgreSQL 的内部实现,包括查询处理、并发控制、WAL、缓冲区管理等核心机制。

      系统与基础设施上首页 5 次 · 2017–2025interdb.jp编辑精选

    打赏支持

    打赏二维码

    觉得有用,请作者喝杯咖啡。

    WeChat

    关注向阳乔木

    微信公众号「向阳乔木推荐看」

    微信公众号「向阳乔木推荐看」二维码

    微信扫一扫;在微信里打开本页时,长按二维码识别。