Live data from Hacker News

Show HN: Tiny 1k Rust binary on Windows

github.com

61–66 of 66 posts

Re: Show HN: Tiny 1k Rust binary on Windows

#61
post #58

Earlier quoted context omitted.

Yeah my choice of words wasn't great. It seams as if the zig std acts as a macro rather than a wrapper. That could just be the aggressive optimization though

What name would you use after seeing the implementation of the functions called? std/debug.zig: pub fn print(comptime fmt: []const u8, args: anytype) void { const held = stderr_mutex.acquire(); defer held.release(); const stderr = io.getStdErr().writer(); nosuspend stderr.print(fmt, args) catch return; } io/writer.zig: pub fn print(self: Self, comptime format: []const u8, args: anytype) Error!void { return std.fmt.fo…

Very well optimized inlined functions?

I didn't actually check the zig std source. I was referring to what I was seeing in radare2 :)

Re: Show HN: Tiny 1k Rust binary on Windows

#62
post #58

Earlier quoted context omitted.

What name would you use after seeing the implementation of the functions called? std/debug.zig: pub fn print(comptime fmt: []const u8, args: anytype) void { const held = stderr_mutex.acquire(); defer held.release(); const stderr = io.getStdErr().writer(); nosuspend stderr.print(fmt, args) catch return; } io/writer.zig: pub fn print(self: Self, comptime format: []const u8, args: anytype) Error!void { return std.fmt.fo…

Very well optimized inlined functions? I didn't actually check the zig std source. I was referring to what I was seeing in radare2 :)

In zig there's a concept of "comptime" -- note that fmt parameter is marked as such. It's more than just inlining.

https://ziglang.org/documentation/master/#comptime

See an example calling firstNPrimes. "When we compile this program, Zig generates the constants with the answer pre-computed." "Note that we did not have to do anything special with the syntax of these functions. For example, we could call the sum function as is with a slice of numbers whose length and values were only known at run-time."

Then see "Case Study: printf in Zig"

Re: Show HN: Tiny 1k Rust binary on Windows

#63
post #53

Earlier quoted context omitted.

Between a 40b strcmp method (If I had/if it was more widely supported I could use sse4.2 strcmp) and ~74b of resolving said exports a couple syscalls sounds pretty nice provided the context switch isn't more expensive than resolving the imports.

Well if you really want to you can get the output handle from the PEB[0]. You can then call NtWriteFile[1] using syscall `0x0008` (Windows 10 x64 only)[2]. [0]: https://processhacker.sourceforge.io/doc/struct___r_t_l___u_... [1]: https://docs.microsoft.com/en-us/windows-hardware/drivers/dd... [2]: https://j00ru.vexillium.org/syscalls/nt/64/

I completely forgot stdout handle is in the PEB! Thanks! After learning how the windows x64 syscall calling convention works I got it working on win10.

https://i.imgur.com/ErHU7Kr.png https://github.com/mcountryman/min-sized-rust-windows/commit...

Re: Show HN: Tiny 1k Rust binary on Windows

#64

Zig actually does a good job of cutting final output bytes automatically , even with standard library use. I think (?) its compiler sort-of implements a more advanced version of Unix strip. Andrew Kelley could probably chime in more on it.

related, this fun blog post by mandejan: https://blog.mandejan.nl/posts/smallest-echo.html

Re: Show HN: Tiny 1k Rust binary on Windows

#65

Earlier quoted context omitted.

The entire exercise is an attempt to compare apples to apples. In your example, both the C bin and Rust bin are using X, GPU, etcetc - so they warrant no distinction. So what is different? What is included in the Rust binary that isn't in the C? Because that's what is being tested in these types of comparisons. This difference may be because some language included inefficient instructions - has bloated includes, etc.…

I’m not attempting to compare apples and oranges. I’m ranting about how almost every time someone posts something about tiny programs (like 100 line JS programs or wherever), someone has to chime in about how they’re able to do something so small because they’re using all these abstractions (code) below them and, as such, it’s not an achievement. Again: it was just a rant.

Specifically that your rant is here because the Parent comment mentioned Libc - but this is because the Rust version isn't using that - but the C lib is.

So it's Apples to Oranges because they're fundamentally doing different things, and yet we're comparing their Line Count. That's not only reasonable, it's necessary if you want an Apples to Apples comparison.

That's why we're not concerned about the code to render with GPU or some other junk - but we are fundamentally talking about two programs that do different things - but then comparing their line count.

Your rant may be valid in other cases, but it seems super off base here. Your rant has, imo, nothing to do with what's happening in people pointing out the discrepancy.

Re: Show HN: Tiny 1k Rust binary on Windows

#66
post #62

Earlier quoted context omitted.

Very well optimized inlined functions? I didn't actually check the zig std source. I was referring to what I was seeing in radare2 :)

In zig there's a concept of "comptime" -- note that fmt parameter is marked as such. It's more than just inlining. https://ziglang.org/documentation/master/#comptime See an example calling firstNPrimes. "When we compile this program, Zig generates the constants with the answer pre-computed ." "Note that we did not have to do anything special with the syntax of these functions. For example, we could call the sum funct…

I'm a little short on time so I didn't read through all of it but, comptime generics sounds similar to how rust compiles generics and comptime parameters are similar to const fns although zig appears to have more control over what is deamed "compile time".
Post reply on HN