4 ms·
If I'm writing code that actually needs to be optimized, then I usually put it into its own object file and tweak the compiler flags as necessary to get the ass
by MichaelBurge 11y ago
If I'm writing code that actually needs to be optimized, then I usually put it into its own object file and tweak the compiler flags as necessary to get the assembly to look the way I want. The C compiler supporting this saves me time.
For any other language except C(Haskell, Java, C++, C#, Go, etc.), I don't actually care that much about compiler performance as long as it does the obvious optimizations. Generally you can look at performance at a higher semantic level as soon as your code starts implying calls to malloc() - and conversely, you can start looking at the assembly as soon as you've removed all calls to malloc() in the offending section.
The other thing that transcends compilers or languages are the actual bits that get stored in memory or on disk. Even if I'm writing Perl, it makes a difference if I'm packing something into a contiguous array or just packing a bunch of pointers or references to all over my heap. Or if I can shave a couple bytes off every record in a hundred million records.
Javascript might be the one exception, since people using it don't have any other choice. I don't know - is there such a thing as an FFI for Javascript, using a browser extension or something?
- gliese1337 11y agoNative objects are probably as close as you come in most implementations. Windows Scripting Host does have a more general ability to call foreign code from inside JScript (the Microsoft implementation of ECMAScript). I used to write quite a bit of JScript code that called out into windows executables and DLLs.
- dclowd9901 11y agoAsm.js lets you write a strictly typed subset of JS. Most prototypes of it are compiled C running (compiled to JavaScript, yes) 3D games. When compiled, Asm hints the JIT so that it can further optimize around the loose typing of JS.
- evincarofautumn 11y ago> put it into its own object file and tweak the compiler flags as necessary This is a good approach, as are finer-grained optimisation pragmas & attributes, #ifdeffed as needed. Ideally, I’d like the compiler to do only cursory optimisations by default, just enough that I can read the assembly and not say “wow, this is stupid”. For anything else, I’d rather have a dialogue with the profiler & compiler heuristics, wherein they suggest optimisations, but I choose which ones I want using optimisation pragmas, and the compiler does the grunt work of program transformation. For example, the compiler would say “this function is only ever called in cold paths; I suggest adding the ‘cold’ attribute” or “this loop can be vectorized; I suggest adding the ‘vectorize’ attribute”.