编程与软件工程nee.lv
我如何将 GTA Online 加载时间缩短 70%
How I cut GTA Online loading times by 70%
2021 — 2024,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
作者逆向分析了 GTA Online 漫长的加载过程,发现瓶颈并不在网络或游戏逻辑,而是一个约 10MB、六万多行的 JSON 文件解析,加上低效的字符串比较和反复调用 strlen 等细节。他写补丁把加载时间缩短了约 70%,Rockstar 随后在官方更新中修复了该问题。
为什么经久不衰:它同时是性能剖析与逆向工程的教科书式案例,也暴露了大公司里没人有权限或余力去修一个“小问题”的组织困境,这些教训至今不过时。
HN 评论精选
震惊于瓶颈竟是 JSON 解析,并质疑 Rockstar 内部为何八年无人发现和修复。
天哪,我只是个很休闲的玩家,当初很期待这游戏,但发售时我决定不想等那么久,等他们修好再说。两年后还是那么慢,我就放弃了。可是……这个?!太难以置信了。我确信很多人就是因为加载时间而离开了这游戏,浪费掉的是以人年计的时间。解析 JSON?!我还以为是某种网络游戏逻辑在找 session magic。如果这是真的,那是我近几年见过的最大的 WTF,而我们才刚过完 2020 年。光靠手头有个二进制文件就做出这样的成果,太惊人了。但 R* 怎么会没做这件事?GTA V 里满是出色的工程。如果瓶颈在 CPU,那里难道没有人会忍不住去查个究竟吗?哪怕性能不关键,耗时远超预期时去搞清内部发生了什么也是很自然的事,而这里它是关键的,几乎直接换算成利润。难以置信。
comboy查看英文原文
Holy cow, I'm a very casual gamer, I was excited about the game but when it came out I decided I don't want to wait that long and I'll wait until they sort it out. 2 years later it still sucked. So I abandoned it. But.. this... ?! This is unbelievable. I'm certain that many people left this game because of the waiting time. Then there are man-years wasted (in a way different than desired). Parsing JSON?! I thought it was some network game logic finding session magic. If this is true that's the biggest WTF I saw in the last few years and we've just finished 2020. Stunning work just having binary at hand. But how could R* not do this? GTAV is so full of great engineering. But if it was a CPU bottleneck then who works there that wouldn't just be irked to try to nail it? I mean it seems like a natural thing to try to understand what's going on inside when time is much higher than expected even in the case where performance is not crucial. It was crucial here. Almost directly translates to profits. Unbelievable.
把它当作通用工程课:剖析、依赖细节、数据结构、代码审查缺一不可。
这就是我来 HN 的原因。我本来要跳过这篇,以为是在讲电子游戏,结果很庆幸读了,每一行都喜欢。能学到的东西太多了:即使没有源码,只要你够烦,你也能做出改变;不喜欢某个东西而源码就在那儿,那就真的去贡献;性能很重要,要会做剖析,用了外部依赖就要搞清它的实现细节;算法与数据结构很重要,常听到开发者说这无所谓,但 hashmap 和数组的差别是实实在在的;认真的代码审查很重要——很可能这段代码是交给初级工程师或实习生写的,小数据集下能跑通,就没人注意到。
segmondy查看英文原文
This is why I come to HN, I was going to skip this because I thought it was about video games, but really glad to have read it, and loved every line of the article. So much to get from this. Even if you don't have the source, you can make a change if you are annoyed enough. If you don't like something, and the source code is out there, really go contribute. Performance matters, know how to profile and if using an external dependency, then figure out their implementation details. Algorithms & Data structures matter, often I see devs talking about how it doesn't matter much but the difference between using a hashmap vs array is evident. Attentive code reviews matter, chances are they gave this to a junior dev/intern, and it worked with a small dataset and no one noticed.
赞赏作者在缺乏完整理解时仍敢打补丁,缓存 strlen 的做法尤其巧妙。
说实话,这些糟糕的代码让我有点被冒犯,但我更佩服这个人的执着。在编译好的程序里定位 bug 已是一回事,在并不完全理解全局的情况下打补丁又是另一回事。缓存 strlen 是个特别聪明的技巧,绕开了一堆更复杂的方案。
singhrac查看英文原文
Honestly, while this horrible code is mildly offensive to me, I'm pretty impressed by this person's persistence. It's one thing to identify a bug in a compiled program, but it's another to patch it without fully understanding what's going on. Caching strlen was a particularly clever trick that sidestepped a bunch of more complicated solutions.
真正值得反思的是组织:没人有权限或时间去修这个显而易见的问题。
这里有个隐含的故事,我觉得相当悲哀:过去八年里,Rockstar 没有任何一个开发者有自主权或余力去自己发现并修复这个问题。
kevinventullo查看英文原文
There’s an implicit story here which I find quite sad that not a single developer at Rockstar in the prior eight years had the autonomy or bandwidth to discover and fix this themselves.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选