6 ms·
Just out of curiosity from someone who started with languages like JavaScript and other languages. But what makes C special for this case? For instance couldn't
by isaiahg 9y ago
Just out of curiosity from someone who started with languages like JavaScript and other languages. But what makes C special for this case? For instance couldn't I achieve the same thing with typed arrays in JavaScript?
Sorry if it's a naive question. My experience with C is limited.
- btrask 9y agoIf you used Node, you would have IIRC around 40MB (edit: 24MB on my system) of memory overhead before your code even started running. If you are CPU-bound, multiply that by the number of cores you want to use.
- vvanders 9y agoNope, the main advantage of C/Rust/D/etc is explicit control of memory allocation and placement. 90% of your program performance is going to be dominated by cache usage(unless you're doing something really dumb). With C you can place things next to each other explicitly so that your prefetcher/etc is automatically pulling in the data you need to the L1 cache. Any ref'd/GC'd language is going to make that really hard(not impossible, but you have to jump through a million hoops like sun.misc.unsafe in Java). Look up Data Oriented Design if you're interested in this stuff, Mike Acton does a great job covering it.
- justin66 9y agoCreating a program that is bound by disk performance and indifferent to l1 cache is not necessarily "really dumb." Premature optimization is a real thing.
- vvanders 9y agoGenerally a cache miss to DRAM is going to be somewhere around 3 orders of magnitude slower than accessing something in L1. All it takes is 4-5 of these and now you're incurring performance hit of ~1ms which gets you into SSD territory[1]. As always, profile before making these optimizations but the OP was asking why something like this isn't possible in managed languages. [1] https://arstechnica.com/information-technology/2012/06/inside-the-ssd-revolution-how-solid-state-disks-really-work/ https://arstechnica.com/information-technology/2012/06/insid...
- pjmlp 9y ago> Any ref'd/GC'd language is going to make that really hard( Not true at all. Oberon, Active Oberon, Component Pascal, Modula-2+, Modula-3, D, System C#, Nim all offer ways to manually control memory outside GC control, just like C and C++. Glad to provide Modula-3 examples to any C tricks you might want to do, or in D if you prefer something more modern.
- vvanders 9y agoYet not a single one of those examples is a mainstream language. So when you finish the project and move on to bigger things I've got a codebase that no one can maintain. Note that I didn't say that it was impossible, just that the ergonomics of GC'd languages don't tend to focus on performance in the ways that languages with explicit memory control do.
- pjmlp 9y agoMost of those languages died due to political reasons and company acquisitions, not because of lack of technical features. GC systems programming languages offer exactly the same explicit control as C does, in unsafe memory blocks. Do you want to shot yourself like C in Modula-3? Declare a variable as UNTRACED REF, 100% like a C pointer. Do you want a C union? Declare a tagged RECORD type. Do you want a packed record to fill you cache line? Compiler alignment pragmas. Allocation of value types on the stack or global memory section? Great, it is the default allocation type. Bit fiddling to prepare a statically allocated buffer for a DMA transfer? UNSAFE code section.
- vvanders 9y ago> Most of those languages died due to political reasons and company acquisitions, not because of lack of technical features. Yet you just talked past my point to give some sort of soliloquy about Modula-3. It doesn't matter how those languages died, it just matters that they did. The ecosystem and number of people who know how to write a language is almost, if not more important than the language when it comes to shipping software.
- dom96 9y agoWait. Isn't D considered a GC'd language? You seem to be implying it's not.