HackerX
HomeRank #61
@TimSweeneyEpic

Programming

@TimSweeneyEpic

View on X
Recommended by 2 HN userstechnical
View on X

Why Hacker News recommends it

5 comments from 2 distinct recommending readers, between 2020 and 2025.

  1. @ryaoRecommends2025
    What you wrote about C versus C++ is largely untrue. C++ is not faster than C, even when “using library functions which use void pointers”. There is nothing about a void pointer that prevents inlining in either C or C++. There is also no “optimized on actual types” for C++ and not C, since everything is compiled into a low level intermediate language in the compiler (typically three-address code). All of the C++ types are absent at that point. The low level intermediate representation is then what receives optimization. For example, GCC will outright inline both bsearch() and the provided comparator in cases where it can see the definition of the comparator, such that there are no function calls done to either bsearch() or the comparator. C compilers will do this for a number of standard library functions and even will do it for non-library functions in the same file since they will inline small functions if allowed to do inlining. When the functions are not in the same file, you need LTO to get the inlining, but the same applies to C++. That said, I have never seen assembly output from a C++ compiler for C++ using C++ specific language features that was more succinct than equivalent C. I am sure it happens, but the C++ language is just full of bloat. C++ templates usually result in more code than less, since the compiler must work much harder to optimize the result and opportunities are often lost. It is also incredibly easy for overhead to be hiding in the abstractions, especially if you have a thread safe class used in a single threaded context as part of a larger multithreaded program. The compiler will not optimize the thread safety overhead away. You might not believe that C++ language features add bloat, so I will leave you with this tidbit: twitter.com/TimSweeneyEpic/status/12230…... Tim Sweeney’s team had C++ code that not only did not use exceptions, but explicitly opted out of them with noexcept. They got a 15% performance boost from turning off exceptions in the compiler, for no apparent reason. C, not having exceptions, does not have this phantom overhead.
    Making C and Python Talk to Each OtherRead the thread
  2. @keldarisRecommends2020
    > which is crazy because there's no cost if you don't raise one This is just false in the general case. The presence (potential or actual) of exceptions often just serves as an optimization barrier in current compilers. That's not to even invoke bizarre but not infrequent issues like this [1]. I too have had codebases that miraculously sped up upon disabling exceptions despite not throwing anything. Identifying the exact causes of these situations is hard and typically not done, because it's far easier to just add a compiler switch and pretend there are no exceptions in C++ and get back to work. Many people in performance sensitive domains just don't find it remotely worthwhile to care about features that have these sorts of difficult to predict and debug costs. When your workflow already consists of writing highly explicit, simple to reason about code that you frequently inspect in disassembled form, exceptions (and RTTI for a host of obvious reasons) are the last thing you'd want to enable. At best it's just extraneous noise in the assembly, at worst you take a sizable perf hit and have no idea why. [1] twitter.com/timsweeneyepic/status/12230…...
    Cost of a thread in C++ under LinuxRead the thread
  3. @kwant_kiddoCites it2023
    The premise is that exceptions should be zero cost to check, however it worries me when profiles like Tim Sweeney says that his code got 15% faster by turning off exceptions [1]. [1]: twitter.com/TimSweeneyEpic/status/12230…...
    Ask HN: Big C++ projects that uses Exceptions and RTTI?
  4. @gameswithgoCites it2020
    Tim Sweeney, creator of Unreal Engine, Epic Megagames, etc, recently had a code base where exceptions were causing problems even when not actively being thrown: twitter.com/TimSweeneyEpic/status/12230…... Quoting him in a follow up tweet: >They weren’t throwing and a disassembly showed no visible artifacts of exceptions. But turning off the possibility of throwing exceptions gained 15% and just made the assembly code tighter with no clear pattern to the improvements.
    Investigating the Performance Overhead of C++ ExceptionsRead the thread
  5. @patrecCites it2020
    twitter.com/timsweeneyepic/status/12230…...
    Orthodox C++Read the thread

More

RSS feed

Keyboard shortcuts