TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Nim binary size from 160 KB to 150 Bytes

145 点作者 def-大约 10 年前

12 条评论

teh大约 10 年前
Today I looked at Nim in a bit more depth because it keeps popping up. I have a slightly uncomfortable feeling about it that I hope is unfounded!<p>To me it looks like it makes the unsafety of c more accessible because of better tooling and nicer syntax. Looking at e.g. [1] there are still pointers, null-pointers etc, just like in c. So now you have a language that looks superficially simple but is actually very dangerous. Compare this to e.g. rust which was the most painful thing I learned recently but I also know that it brings something fundamentally new to the table.<p>Anyway, there&#x27;s a lot I don&#x27;t understand about Nim and I&#x27;d be happy to see evidence to the contrary.<p>[1] <a href="http:&#x2F;&#x2F;nim-lang.org&#x2F;0.11.0&#x2F;tut1.html#advanced-types-reference-and-pointer-types" rel="nofollow">http:&#x2F;&#x2F;nim-lang.org&#x2F;0.11.0&#x2F;tut1.html#advanced-types-referenc...</a>
评论 #9486200 未加载
评论 #9486323 未加载
评论 #9485975 未加载
ilitirit大约 10 年前
I&#x27;ve tried Rust, Nim and Go and I prefer Nim. But this could also be because of my background as a C&#x2F;C++ programmer, and my particular requirements (general purpose programming language that doesn&#x27;t try to hold my hand <i>too</i> much).<p>There are things I don&#x27;t like about the language (eg. case-insensitivity), but overall if I had to choose a newish language for a new task, I&#x27;d choose Nim over Rust and Go. (However, if you threw D into the equation I&#x27;d probably go with D simply because I feel it&#x27;s slightly more mature).<p>Incidentally, the way I tried to teach myself Nim (and to see if the language was usable for creating small Windows apps) was to write a WinApi program. It took about the same or less effort as what it would have taken me in C&#x2F;C++, but it just felt much safer and more pleasant to work with.
评论 #9488881 未加载
masklinn大约 10 年前
Comparison summary between the Rust inspiration and the Nim version:<p>* Nim&#x2F;GCC gains 2 bytes by smartly reusing the previously set AX register&#x27;s value to set DI where Rust&#x2F;Clang uses an immediate<p>* Nim can&#x27;t express that stuff after the EXIT syscall is unreachable and wastes a byte on a RETQ.
Fastidious大约 10 年前
I read this, and wonder why software has gotten so fat? Any simple application these days is easily on the few dozen of MB, most a few hundred, with a few on a few GB in size. Why aren&#x27;t we streamlining software to reduce its size? I understand we have gotten &quot;rich&quot; on storage, but if the trend continues...<p>I am sure many portable devices would benefit if applications were trimmed down.
评论 #9487511 未加载
评论 #9490319 未加载
评论 #9487810 未加载
_blrj大约 10 年前
I love these articles; I make sure to bookmark them just in case one day I want to build binaries that do nothing.
评论 #9487139 未加载
onedognight大约 10 年前
This post is Nim specific, but the key ideas for getting to a small binary (optimize for size, remove the standard library, avoid compiler main() &#x2F; crt0 baggage by defining _start, use system calls directly) are the same in C, C++, Rust, etc.
bonesmoses大约 10 年前
I like the end result. However, it makes me wonder just why it&#x27;s so acceptable that simple programs like this even compile down to a 160KB executable in the first place.<p>The actual active code is essentially some text and an interrupt. That much, at least, should be language independent. Are modern compilers incapable of discarding unreferenced code, or am I missing something?
评论 #9487277 未加载
killercup大约 10 年前
&gt; (1 byte smaller than in Rust)<p>Nice achievement! The article is quite the journey through various build parameters, switching gcc for clang and glibc for musl along the way. In the end, the secret sauce is syscalls and custom linking, though (as always with this kind of thing).
thom_nic大约 10 年前
This seems mostly useful in highly constrained embedded environments (AVR, MSP430, ARM M0, PIC etc.) Unfortunately it seems like none of these &quot;modern&quot; system languages (Nim, Rust) seem to be putting too much effort towards embedded platforms :(
评论 #9486622 未加载
评论 #9486747 未加载
评论 #9486426 未加载
jug大约 10 年前
&gt; Who needs error handling when you can have a 6 KB binary instead<p>Haha!<p>What I found was most impressive was the small binary even without the tricks.
delinka大约 10 年前
&quot;The speed optimized binary is much smaller...&quot;<p>Did I miss where he optimized for speed?
评论 #9486049 未加载
评论 #9486152 未加载
评论 #9486061 未加载
cristaloleg大约 10 年前
WOW. 10&#x2F;10
评论 #9486488 未加载