Live data from Hacker News

Clang Format Tanks Performance

travisdowns.github.io

31–40 of 156 posts

Re: Clang Format Tanks Performance

#31

Author here, happy for any feedback. I'll own up to misleading-and-possibly-clickbait title, I just gave up trying to think of anything better without revealing the conclusion.

I'm going to take the contrarian view here, and say it's not clickbait.

I admit that I'm not a C++ expert, but naively I would never have expected clang-format to have any effect on my code. If you stopped and suggested header re-ordering to me my first thought would have been "I guess it must not do that. Maybe in practice header re-ordering doesn't actually matter with reasonable code?".

The title here doesn't describe the contents of the article, but it describes a very important consequence of it that C++ programmers should be aware of. It gives a specific example of the consequence. I'm ok with that.

Re: Clang Format Tanks Performance

#32

Earlier quoted context omitted.

Just to make sure I'm understanding this correctly: the performance issue you found actually amounts to include-order dependent behavior in GCC and glibc; clang doesn't really have anything to do with anything here except that you used its code formatter to sort your include statements. If that's the case, the clickbait-y headline's bordering on useless, since the performance differences here have nothing to do with…

I'm talking about clang-format, a formatting tool for C and C++ code, which has nothing to do with compiling your code with clang. You can use it with any compiler. That said, the title is still a lie in that clang-format is not really at a fault here at all: clang-format triggered the issue on my codebase, by sorting header files, and this in turn triggered a libc performance issue. So as I initially say it, a commi…

The title would be a /little/ clearer with a dash between Clang and format.

Re: Clang Format Tanks Performance

#33
post #5

Earlier quoted context omitted.

clang format can tank performance” would, IMO, not decrease the number of people who click the link, yet remove the clickbait.

Could be, but I feel it would equally dishonest? This really has nothing to do with clang-format: I only mention that once (twice with an update: where clang format actually helps because it reorders stdlib.h after ctype.h) - it's all about header include order.

Maybe someone should make a tool that randomly reorders your header includes until optimal performance is found.

Re: Clang Format Tanks Performance

#34

Earlier quoted context omitted.

I'm talking about clang-format, a formatting tool for C and C++ code, which has nothing to do with compiling your code with clang. You can use it with any compiler. That said, the title is still a lie in that clang-format is not really at a fault here at all: clang-format triggered the issue on my codebase, by sorting header files, and this in turn triggered a libc performance issue. So as I initially say it, a commi…

The title would be a /little/ clearer with a dash between Clang and format.

Or "header inclusion order may affect performance." If someone points to this as a reason not to use clang-format...

Re: Clang Format Tanks Performance

#35
post #20

Earlier quoted context omitted.

Oh, I don't really have any argument about what titles you should put on your own writing. It's your writing, if you feel its narrative purpose is served by an intricate web of title feints, line noise, whatnot, more power to you. I'm just explaining the HN title rules, you can see them here (do a find title): https://news.ycombinator.com/newsguidelines.html There's nothing in there about titles having to be 'informa…

Got it, I didn't understand you were talking about HN titles, rather than the blog post title. I didn't submit it to HN so I can't comment on the title choice, other than say it at least reflects the literal title of the page which I guess would be the default when submitting. I tend to outsource my comments to HN, since my blog is a github pages static site and introducing comments without tracking and ads is a pain…

Right, technically, fixing the title in this case would have been on the poster. Then there'd probably be a long subthread about why the title was changed so drastically. Title-lawyering is a professional metasport around here, as has been amply demonstrated.

Re: Clang Format Tanks Performance

#36
post #31

Author here, happy for any feedback. I'll own up to misleading-and-possibly-clickbait title, I just gave up trying to think of anything better without revealing the conclusion.

I'm going to take the contrarian view here, and say it's not clickbait. I admit that I'm not a C++ expert, but naively I would never have expected clang-format to have any effect on my code. If you stopped and suggested header re-ordering to me my first thought would have been "I guess it must not do that. Maybe in practice header re-ordering doesn't actually matter with reasonable code?". The title here doesn't desc…

I agree with most of that, although as the author I think it's still clickbait in the sense that:

1) clang-format is not really at fault here at all - the same effect could have happened by adding a new header, reordering the headers manually, switching to a system with a different libc version or a different transitive header include tree, etc.

2) The title doesn't tell you wtf is up. You have to get at least half way through the post to figure that out. It's in the vein of "This one food could wreck your health" posts.

That said, other aspects of clickbait are advertising or monetization to profit from the clicks. Except for the crypto mining bot I load into your browser, and which subsequently writes itself to your MBR or UEFI partition, I have no ads, affiliate links, patreon-alikes or other monetization vectors.

Re: Clang Format Tanks Performance

#38

Link time inlining would solve this.

In a sense, yes - specifically if libc could be link-time inlined.

I don't think many people are proposing that for libc though because it would shut down the possibility to patch libc for anything that has been link-timed inline, and more generally expose the internal implementation of libc in a way that will make evolving it very difficult.

That is, link-time inlining will see a lot more use within an application before it will ever apply to system libraries.

Re: Clang Format Tanks Performance

#39

Author here, happy for any feedback. I'll own up to misleading-and-possibly-clickbait title, I just gave up trying to think of anything better without revealing the conclusion.

I clicked because of the title and laughed when I read the reason, don't sweat about anyone accusing you of clickbait

Re: Clang Format Tanks Performance

#40

Earlier quoted context omitted.

I'm talking about clang-format, a formatting tool for C and C++ code, which has nothing to do with compiling your code with clang. You can use it with any compiler. That said, the title is still a lie in that clang-format is not really at a fault here at all: clang-format triggered the issue on my codebase, by sorting header files, and this in turn triggered a libc performance issue. So as I initially say it, a commi…

The title would be a /little/ clearer with a dash between Clang and format.

Good point, I put a hyphen a few places but not everywhere nor in the title. It seems hyphen is definitely the standard though.

Fixed now [1], although the HN title will remain hyphen-free free I guess.

---

[1] https://github.com/travisdowns/travisdowns.github.io/commit/...

Post reply on HN