this post was submitted on 28 Sep 2024
19 points (100.0% liked)

Rust

5805 readers
106 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
 

A short post on how variable names can leak out of macros if there is a name collision with a constant. I thought this was a delightful read!

top 3 comments
sorted by: hot top controversial new old
[–] livingcoder@programming.dev 5 points 1 hour ago (1 children)

This was a great post, but is the last state of the macro actually bad for performance in any way? I get that it's ugly (and we should only choose to make code less readable like this when there's actually an issue) but is it worse for runtime performance?

[–] TehPers@beehaw.org 2 points 11 minutes ago

Adding a single unused function should no effect on runtime performance. The compiler removes dead code during compilation, and there's no concept at runtime anyway of "creating a function" since it's just a compile-time construct to group reusable code (generally speaking - yes the pedants will be right when they say functions appear in the compiled output, to some extent).

Anyway, this can all be tested on Godbolt anyway if you want to verify yourself. Make a function with and without a nested unused function and check the output.

[–] ExperimentalGuy@programming.dev 8 points 2 hours ago

That was such a cute lil post