LWN: Comments on "Amit: How new-lines affect the Linux kernel performance" https://lwn.net/Articles/767884/ This is a special feed containing comments posted to the individual LWN article titled "Amit: How new-lines affect the Linux kernel performance". en-us Fri, 17 Oct 2025 18:12:36 +0000 Fri, 17 Oct 2025 18:12:36 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Use built-ins? https://lwn.net/Articles/769106/ https://lwn.net/Articles/769106/ Hi-Angel <div class="FormattedComment"> I wonder, can these problems be worked around by using gcc built-ins for assembly instructions instead of straight writing up the assembly? I bet it would be more readable too, besides working well with optimizations.<br> </div> Mon, 22 Oct 2018 07:24:13 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/768275/ https://lwn.net/Articles/768275/ kpfleming <div class="FormattedComment"> If the std::string object is itself 'const', not just the literal character array it was constructed from, then indeed there is no need for any work to be done at destruction time (since the only work which could be done would be to free the heap storage which had been allocated, but none will be allocated for a std::string which is const at compile time).<br> </div> Fri, 12 Oct 2018 18:00:22 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/768121/ https://lwn.net/Articles/768121/ welinder <div class="FormattedComment"> <font class="QuotedText">&gt; The problem is it's often not possible for the compiler to tell if it needs destruction or not.</font><br> <p> In general I'd agree, but here I actually think that it would be undefined behaviour to change the string.<br> <p> However, if I am wrong on that, the right thing to do would be to inline the test for the normal case (that does nothing) and handle the exceptional case non-inlined. That's 5 instructions instead of 50, so saving of ~200 bytes of code per string.<br> <p> The compiler's analysis problem gets so much simpler if being right 100% of the time is not a requirement.<br> </div> Thu, 11 Oct 2018 14:45:44 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/768102/ https://lwn.net/Articles/768102/ roc <div class="FormattedComment"> They're not really comparable. "ping" is something that some sites actually asked for, and therefore presumably want to use.<br> </div> Thu, 11 Oct 2018 04:17:07 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/768101/ https://lwn.net/Articles/768101/ plugwash <div class="FormattedComment"> <font class="QuotedText">&gt; that doesn't need destruction</font><br> <p> The problem is it's often not possible for the compiler to tell if it needs destruction or not. As soon as you pass a pointer or reference to the string to a function the compiler has to consider the possibility that said function could replace the contents of the string with longer contents that do require destruction.<br> </div> Thu, 11 Oct 2018 00:46:38 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/768080/ https://lwn.net/Articles/768080/ flussence <div class="FormattedComment"> ping is broken for the same reason DNT is: one browser forced a bad default without informed user consent (in DNT's case, MSIE), rendering it useless for opting out of the status quo, which was the whole point of these to begin with.<br> <p> The worst offender in recent months is Chrome, which keeps adding “interventions” that forcibly break standard HTML and web APIs in the name of battery life or some other vague clickbait that makes for cute blog headlines. The result is that correctly written pages are broken, corporate junk adds another quarter-megabyte of bloat per page, exploiting loopholes in the browser, and users get shafted.<br> </div> Wed, 10 Oct 2018 19:36:19 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/768008/ https://lwn.net/Articles/768008/ Sesse <div class="FormattedComment"> So, your fix for automatically inlining too little is to never automatically inline at all? That hardly sounds like it fixes the issue.<br> </div> Wed, 10 Oct 2018 09:12:35 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/768006/ https://lwn.net/Articles/768006/ Felix.Braun <div class="FormattedComment"> Thank you for the link to the mailing list thread. Actually, it seems that they have already worked out a solution, that works for both the GCC maintainers as well as the kernel guys.<br> </div> Wed, 10 Oct 2018 08:37:21 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/768001/ https://lwn.net/Articles/768001/ joib <div class="FormattedComment"> TBH, ping seems as hopelessly naive and doomed to fail as DNT.<br> <p> It's all-out war between privacy and advertisers; measures which are easily circumvented are pointless.<br> </div> Wed, 10 Oct 2018 05:47:29 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767994/ https://lwn.net/Articles/767994/ roc <div class="FormattedComment"> Yeah, that was a good example of how pressure for vocal but ignorant "privacy advocates" made things worse for everyone.<br> </div> Wed, 10 Oct 2018 02:08:02 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767993/ https://lwn.net/Articles/767993/ roc <div class="FormattedComment"> Not really because the 'ping' attribute is supposed to send the ping in parallel with the page navigation, to minimize delay. But navigating away from the page will cancel any HTTP requests triggered by scripts in that page.<br> </div> Wed, 10 Oct 2018 02:07:06 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767972/ https://lwn.net/Articles/767972/ epa <div class="FormattedComment"> I wonder whether 'ping' could be implemented by a Javascript library, so the HTML source could remain readable. (And users who have Javascript turned off would use the page as normal without pinging the mothership.)<br> </div> Tue, 09 Oct 2018 18:59:26 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767968/ https://lwn.net/Articles/767968/ ballombe <div class="FormattedComment"> <font class="QuotedText">&gt; The fix would be not to inline at all, unless the 'inline' compiler directive is used.</font><br> <p> Compilers have been inlining static functions since much before the inline keyword was introduced.<br> It is quite common for an 'ordinary' C function to use macros that use inline asm.<br> Almost nobody write true asm function anymore because they cannot be inlined.<br> <p> your proposal is not realistic.<br> </div> Tue, 09 Oct 2018 18:26:14 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767966/ https://lwn.net/Articles/767966/ jwilk Run this in the web console to fix the links: <pre> for (let a of document.querySelectorAll('a[href*="/url?"')) { a.href = decodeURIComponent(a.href.match(/[?]q=([^&amp;]+)/)[1]); } </pre> Tue, 09 Oct 2018 17:42:20 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767955/ https://lwn.net/Articles/767955/ iabervon <div class="FormattedComment"> It seems like it wouldn't be hard to have a minimal assembly parser. It would only need to be able to list the instructions (as opposed to labels, directives, blank lines, comments, etc) in assembly languages that GCC can generate code for. That still wouldn't determine how much machine code the assembly corresponds to, particularly after link-time optimization, but it would probably give as good estimates for inline assembly as the estimates for C.<br> </div> Tue, 09 Oct 2018 17:38:10 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767963/ https://lwn.net/Articles/767963/ anadav Google sites has been a terrible choice, which I made a long time ago - sorry for that. I copied the blog-posts to <a>https://blog.amit.zone/</a> for your convenience. Tue, 09 Oct 2018 17:24:50 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767962/ https://lwn.net/Articles/767962/ anadav <div class="FormattedComment"> The overhead is indeed not that great. But as new features that use inline assembly are added for performance (see the "patchable constants" RFC, for example), it might become a bigger issue.<br> </div> Tue, 09 Oct 2018 17:20:47 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767930/ https://lwn.net/Articles/767930/ ibukanov <div class="FormattedComment"> They can use a better heuristic. For example, one can assign weights to the parsed tree nodes based on averages derived from a large code base and then count the totals weight for the function. It is not ideal but is way better then counting lines or statements. <br> </div> Tue, 09 Oct 2018 14:04:53 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767927/ https://lwn.net/Articles/767927/ welinder <div class="FormattedComment"> <font class="QuotedText">&gt; How can it reasonably be fixed?</font><br> <p> It can be fixed by allowing code to override cost for such a statement.<br> <p> However, the whole cost-based inlining heuristic thing is a bit of a hack and it is not working very well in general.<br> <p> For example -- something I have been looking into lately -- when using C-style strings in places where C++ wants an std::string. (That's C++ and not C, but the front end should not really matter for the purposes of discussing inlining.) Constructing a std::string from a constant string of 15 characters or fewer should be a simple matter of poking the right values into the std::string structure, no dynamic memory allocation involved. That is not, however, what gcc does. The decision on whether to inline depends not only on the string [reasonable] but also on other strings used in the same file [weird]. I suspect the phase of the moon plays a role too.<br> <p> And for good measure, the destruction of that std::string (that doesn't need destruction) is fully inlined. That adds ~50 instructions per string and does nothing.<br> </div> Tue, 09 Oct 2018 12:49:26 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767925/ https://lwn.net/Articles/767925/ mlopezibanez <div class="FormattedComment"> The discussion continues here: <a rel="nofollow" href="https://gcc.gnu.org/ml/gcc/2018-10/msg00034.html">https://gcc.gnu.org/ml/gcc/2018-10/msg00034.html</a><br> <p> I don't think it will get "fixed" in the GCC side. These communications between Kernel and GCC follow a classical pattern, and it usually ends with the kernel applying a work-around because there is no easy fix, contrary to what is initially claimed, and the kernel devs are (understandably) not interested in "fixing" GCC.<br> <p> </div> Tue, 09 Oct 2018 12:40:50 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767924/ https://lwn.net/Articles/767924/ oever <p>In this case the link can be trivially rewritten by calling the JavaScript function <tt>decodeURIComponent()</tt> on the URI query value <tt>q</tt>.</p> <p><tt>decodeURIComponent("https%3A%2F%2Flkml.org%2Flkml%2F2018%2F10%2F4%2F25")</tt></p> <p><tt>"https://lkml.org/lkml/2018/10/4/25"</tt></p> Tue, 09 Oct 2018 11:52:58 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767923/ https://lwn.net/Articles/767923/ excors <div class="FormattedComment"> The article points out that explicit inline markers like __attribute__((always_inline)) don't work very well when you have some wrapper function that calls the inlined function, because the wrapper function won't get inlined unless you remember to explicitly mark it too. And if it's wrapping an arch-dependent function, maybe it should be inlined on some archs and not on others, and maybe that decision should change when the code is refactored years later - it's very hard for the programmer to keep track of that and mark everything correctly. For any problem larger than a single function, the compiler is likely able to make better decisions than a human because it knows precisely what code is being compiled and how it interacts with all the other code.<br> </div> Tue, 09 Oct 2018 11:35:09 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767922/ https://lwn.net/Articles/767922/ excors <div class="FormattedComment"> Yes, and some users complained vociferously about Firefox violating their privacy by supporting ping (even if it had an opt-out for privacy-conscious users), so Firefox disabled it by default, making it highly ineffective, so now all sites continue to implement their own link tracking systems that obscure the URLs and are less efficient and can't be disabled by privacy-conscious users.<br> </div> Tue, 09 Oct 2018 11:16:24 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767921/ https://lwn.net/Articles/767921/ mageta <div class="FormattedComment"> That's a bit melodramatic. Its not "destroying" the performance of Linux, as the original author says in the patch-notes:<br> <p> <font class="QuotedText">&gt; I ran some limited number of benchmarks, and in general the performance</font><br> <font class="QuotedText">&gt; impact is not very notable. You can still see &gt;10 cycles shaved off some</font><br> <font class="QuotedText">&gt; syscalls that manipulate page-tables (e.g., mprotect()), in which</font><br> <font class="QuotedText">&gt; paravirt caused many functions not to be inlined. In addition this</font><br> <font class="QuotedText">&gt; patch-set can prevent issues such as [1], and improves code readability</font><br> <font class="QuotedText">&gt; and maintainability.</font><br> </div> Tue, 09 Oct 2018 11:12:19 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767920/ https://lwn.net/Articles/767920/ epa <div class="FormattedComment"> Didn't browsers like Firefox add a 'ping' attribute on links just so that you could get this traceback without ugly URI mangling and extra round trips? (And 'ping' is something the user can choose to turn off, of course.)<br> </div> Tue, 09 Oct 2018 10:57:17 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767918/ https://lwn.net/Articles/767918/ epa <div class="FormattedComment"> The fix would be not to inline at all, unless the 'inline' compiler directive is used. That would make the behaviour predictable and I'm sure that most projects (like Linux) would prefer that explicit approach over the supposed convenience of having the compiler guess what assembly to inline. When you write inline assembly you are already choosing to get obsessive about details, so having to specify the inline behaviour isn't much of an extra burden. Ordinary C functions, where the compiler has much more of a clue about how big they are, could still be inlined heuristically.<br> <p> </div> Tue, 09 Oct 2018 10:55:25 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767917/ https://lwn.net/Articles/767917/ excors <div class="FormattedComment"> How can it reasonably be fixed? My non-expert understanding is that GCC essentially translates a .c file into a .s file, then passes it to the binutils assembler; and inline assembly is just an opaque string that gets pasted into that .s file. GCC simply doesn't have an assembly parser, and even if it did then it couldn't parse an inline assembly statement in isolation because of macros defined in other inline assembly statements. I don't see how it can get a reliable estimate of the number of instructions, except with some multi-pass process like PGO.<br> </div> Tue, 09 Oct 2018 10:01:15 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767916/ https://lwn.net/Articles/767916/ joib <div class="FormattedComment"> That blog says on the bottom "Made with the new Google Sites, an effortless way to create beautiful sites.". So probably the URL's get rewritten so that the mothership can hoover up some information when someone clicks on a link.<br> </div> Tue, 09 Oct 2018 09:39:49 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767914/ https://lwn.net/Articles/767914/ halla <div class="FormattedComment"> What a curious way of linking does that article use "<a href="https://www.google.com/url?q=https%3A%2F%2Flkml.org%2Flkml%2F2018%2F10%2F4%2F25&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNHmatTE6Tz8WWZScCVnHEP_XkmTLw">https://www.google.com/url?q=https%3A%2F%2Flkml.org%2Flkm...</a>" instead of "<a href="https://lkml.org/lkml/2018/10/4/25">https://lkml.org/lkml/2018/10/4/25</a>"<br> </div> Tue, 09 Oct 2018 08:23:15 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767913/ https://lwn.net/Articles/767913/ ledow <div class="FormattedComment"> Yeah... "guessing" how large code is by how many line returns in it seems the dumbest hack I've heard of in a long time.<br> <p> The sort of thing you slap into the code "to solve the problem" with the intention of actually putting in proper code at some point, but surely not anything that a group of professional programmers should be leaving lying around in anything more than a prototype.<br> <p> If you need to make a decision based on the compiled size of code... then you need to compile that code and find out.<br> <p> In this case it's only a test for "is this big enough to inline" but that's enough to destroy performance of an entire OS if you get it right.<br> <p> But how much code in gcc is using this to size things like buffers, and introduce potential overflows and security problems if it gets the metric wrong?<br> <p> It's very shoddy.<br> </div> Tue, 09 Oct 2018 07:54:31 +0000 Amit: How new-lines affect the Linux kernel performance https://lwn.net/Articles/767909/ https://lwn.net/Articles/767909/ flussence <div class="FormattedComment"> This looks like a bit of a egg-on-face moment for GCC… the same thing happened with one (or more?) of the mainstream web browsers, which wouldn't JIT compile some JS code unless the source was minified, ignoring the size of the IR. At least now it'll get fixed.<br> </div> Tue, 09 Oct 2018 02:55:32 +0000