5 ms·
I'm in violent agreement. To avoid the costs of serialization and deserialization on a per-request basis, I built a little object system that stored all its in
by barrkel 13y ago
I'm in violent agreement.
To avoid the costs of serialization and deserialization on a per-request basis, I built a little object system that stored all its instance data in a byte array. All internal references were offsets from the start of the array, but what made it fast was that I could read and write in it using raw pointers.
I then recycled the byte arrays to avoid GC pressure, as many were just over the edge of the large object heap, only collectable with gen2 scans.
I had a version working with manually allocated buffers, but it wasn't any faster - GC overhead was only 2% or so.
- CCs 13y agoHow CLR ninja skills are better than C++ ninja skills? Both might kill average developers. The named C# implementation came from .NET experts and an army of consultants from Microsoft. The final advice was "yes, C# is easier to develop, but it comes with a price - just pay the price and drop in some additional servers".
- mwcampbell 13y agoThe crucial difference is that C# is memory-safe by default, and for most code, this is fine. As another commenter said, manual memory management is available as an escape hatch from the garbage collector if you need it. To extend the Edward Scissorhands analogy, with C#, you can use scissors when you need them, but with C++, your hands are scissors, so you'd better be careful all the time.
- lmm 13y agoBetter to be safe for everyone and fast for experts than the other way around.
- MichaelGG 13y agoYes, as everyone says: measure measure measure! Sometimes, despite the CLR generating what looked like terrible x64, it went faster than my alternatives. Performance can be counter-intuitive sometimes, esp. in a somewhat complicated environment like the CLR. Although, it's safe to say if you have 20GB heaps and are doing Gen2s often, then you might wanna investigate another approach ;)
- CCs 13y agoGreat! Can you prove it? There's a benchmark: http://www.techempower.com/benchmarks/#section=data-r6&hw=winec2&test=db http://www.techempower.com/benchmarks/#section=data-r6&hw=wi... Go-lang is roughly 10 times faster than ASP.NET (implemented as recommended by Microsoft). Skipping the ORM doubles the speed, but then you lose most of the components, so I'm not sure that's a realistic optimization. Can you do better?
- MalcolmEvershed 13y agoIn case anyone is curious what is going on with those ASP.NET TechEmpower benchmarks: The TechEmpower benchmarks are all about how much overhead you can eliminate. I profiled the CPU-bound ASP.NET TechEmpower benchmarks and most of the time is spent in IIS<->ASP.NET overhead. After I removed IIS and ASP.NET by just using the .NET HttpListener class [0], the result (on my machine) gives Go a run for its money. Hopefully these results will show up in the next Round that TechEmpower runs. I profiled the .NET TechEmpower tests that access PostgreSQL and MySQL and found that the database drivers had a lot of unnecessary overhead, for example the Oracle .NET MySQL provider does a synchronous ping to the MySQL Server for every connection, even if it's pooled. Plus, it sends an extra 'use database;' command. [1] The PostgreSQL provider also sends extra synchronous commands for every connection. [2] [0] https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/HttpListener https://github.com/TechEmpower/FrameworkBenchmarks/tree/mast... [1] https://github.com/TechEmpower/FrameworkBenchmarks/issues/315 https://github.com/TechEmpower/FrameworkBenchmarks/issues/31... [2] https://github.com/TechEmpower/FrameworkBenchmarks/pull/325#commitcomment-3373154 https://github.com/TechEmpower/FrameworkBenchmarks/pull/325#...
- CCs 13y agoSo C++ is bad because certain functions should be avoided and has no garbage collector. (With C++11 STL normally there's no need for manual memory management or naked pointers.) C# is good, just you should avoid the garbage collector and 90% of the standard library. Roll your own web server, raw sql commands, have manual memory management, use undocumented calls, emit byte code and there you have: almost 40% of the C++ performance. I'm the only one who thinks this does not make any sense?