News for hackers. Stuff that matters.
Re:High-performance .NET by example: Filtering bot traffic by hdhzy on Monday April 24, 2017 @10:22AM (#14184524)
Excellent post showing how to correctly improve code w.r.t. performance using the scientific method: hypothesis, measuring the baseline, change, measuring effect with real tools, real code.

Thanks for sharing!

Re:High-performance .NET by example: Filtering bot traffic by Someone1234 on Monday April 24, 2017 @11:31AM (#14185081)
I also found it an interesting post in that it kind of inadvertently proves that for most situations you shouldn't optimise to this extent.

Meaning, yes, the OP got impressive performance improvements but the code is also completely unreadable and utilises unsafe code sections which could expose you to security problems/memory leaks/memory corruption. Not to mention they've recreated and will need to maintain an in-house version of the Dictionary class.

Their first optimisation (from Enumerator to List and Any() to Count()) are something every codebase could use. Most of their other optimisations make the code a maintenance minefield.

Plus programmers are expensive. Hardware is cheap. Why spent time on harder code to write that's also harder to maintain in the medium to long term when instead you could just throw money at hardware and call it a day? Just food for thought, not really a criticism in and of itself.

PS - Please don't take this post too seriously. I am not really being critical, just playing devil's advocate. I actually enjoyed the linked article a lot.

Re:High-performance .NET by example: Filtering bot traffic by jackmott on Monday April 24, 2017 @01:13PM (#14186044)
Hardware might be cheap at some scales, but what if your service gets popular?

What it latency for a single request can't be improved with more cores?

What if your product is used by consumers who may have old hardware? or phones, or watches, or laptops and they want their battery to last?

What if you consistently practiced at making high performance code, maybe then it wouldn't seem "unreadable" to you any more?

What if Linq-like higher order functions weren't slow? https://github.com/jackmott/LinqFaster

What if slow software was common today because of modern attitudes, and I wasn't seeing any increase in stability or features to show for it?

Re:High-performance .NET by example: Filtering bot traffic by deanCommie on Monday April 24, 2017 @03:02PM (#14187028)
> what if your service gets popular?

Then re-design for map-reduce, and scale horizontally

> What it latency for a single request can't be improved with more cores?

Then look into pre-computing and caching

> What if your product is used by consumers who may have old hardware? or phones, or watches, or laptops and they want their battery to last?

I thought we were talking about server requests? If we are, then offload this work to the server

> What if you consistently practiced at making high performance code, maybe then it wouldn't seem "unreadable" to you any more?

But it's not all about you. Unless you're working on a pet project, or you have the credibility and reputation to be the final call on a significant open source project, you might get hit by a bus tomorrow. Or, if you do a really good job, your company will need you to be a force multiplier to teach a dozen others to try to imitate you. Even if you're a "10x" programmer.

And by the way, when you optimize code THIS much, any refactoring or tweaks to new features cause your optimizations to get tossed out, and you have to start over from scratch.

> What if Linq-like higher order functions weren't slow? https://github.com/jackmott/LinqFaster

https://github.com/jackmott/LinqFaster#limitations

> What if slow software was common today because of modern attitudes, and I wasn't seeing any increase in stability or features to show for it?

Except you are, and you don't even realize it. Optimizations like this blog post matter a LOT on client software. Be it apps, or websites - anything run on the client will need this kind of attention sometimes.

But this guy is writing server software. Micro-optimizing on the server side the way he is doing is silly.

Re:High-performance .NET by example: Filtering bot traffic by alexandrnikitin on Monday April 24, 2017 @03:32PM (#14187321)
> But this guy is writing server software. Micro-optimizing on the server side the way he is doing is silly.

Khm... What if you have millions of requests per second with tight latency requirements measured in milliseconds; and a bunch of business logic to fit into that. Such optimizations aren't so silly. There are different scenarios on both client and server sides.

Re:High-performance .NET by example: Filtering bot traffic by dahauns on Monday April 24, 2017 @06:02PM (#14188797)
Heh. You mean, like the example in the article? :)
Re:High-performance .NET by example: Filtering bot traffic by ro_sharp on Tuesday April 25, 2017 @03:42AM (#14191522)
I'd suggest that OLTP applications where non-trivial amounts of state are shared between transactions are a reasonable counterexample where single core performance optimisation really matters.
Re:High-performance .NET by example: Filtering bot traffic by pc86 on Monday April 24, 2017 @03:29PM (#14187298)
I don't want to pick one single thing about your response, because I agree with a good portion of it, but if you're developing for watches you're probably going to care about performance from the start and not have the GP's (completely valid in certain scenarios) attitude.
Re:High-performance .NET by example: Filtering bot traffic by drewmate on Monday April 24, 2017 @12:11PM (#14185438)
I wonder if good VCS could solve this problem. For instance, if he documented each step with comments/commits in the code as well as he did for this blog post, it would be easy to go back and see not only why he did what he did, but the much more readable (albeit less performant) original code.

It seems like most git guis are pretty commit-focused. I'm not sure of any way to do it in the command line (though it must be possible) but it would be nice to highlight a section of code in your IDE and have git give you a history of just those lines (or that function) as far back as you want to go.

Re:High-performance .NET by example: Filtering bot traffic by osd on Monday April 24, 2017 @12:35PM (#14185674)
No, no no no.

I cannot believe that you are honestly saying a 2x increase to throughput in production is something you "shouldn't take seriously" because the code isn't as readable as it was before.

Programmers are expensive. Hardware is cheap. That doesn't justify completely throwing out the window any performance increasing changes just because a fresh college grad won't be able to understand what's going on within 10 minutes.

Re:High-performance .NET by example: Filtering bot traffic by Someone1234 on Monday April 24, 2017 @01:54PM (#14186397)
> I cannot believe that you are honestly saying a 2x increase to throughput in production is something you "shouldn't take seriously" because the code isn't as readable as it was before.

I've worked on large and old codebases for years. I've seen plenty of examples of where a "clever" programmer has optimised the heck out of a section of code, made it completely unmaintainable, and as a result forced a re-write (the resulting code, which was slower, was also easier to maintain and reason about).

"Production" is a meaningless rallying cry. Everything is production sooner or later. Not everything needs to be fast, although there are critical areas of a typical project that do. It is really a question of code quality relative to performance, unless performance itself is actually causing you problems. Typically these overeager performance fixes are done to code preemptively.

This is all fine for your pet and toy projects, go work on something enterprise grade. Big code means clean code. I'd take ten lines of clean easy to consume code over one "clever" line of genius.

Re:High-performance .NET by example: Filtering bot traffic by hdhzy on Monday April 24, 2017 @03:40PM (#14187407)
I don't know your experiences but the "performance optimizations" that I've seen lacked obvious technical support around it. Usually people thought "it will be faster" without using profiler (sin no 1) or did not properly isolate and control the performance critical part of the code (making performance tests part of the build etc.). But these are other issues separate from optimizing code.

The usual caveat of making code correct, readable and then fast in this order of course also applies :)

[dead]
Re:High-performance .NET by example: Filtering bot traffic by Someone1234 on Monday April 24, 2017 @04:31PM (#14188011)
That sounds more like a personal attack than a constructive response to the topic.

I only brought up large (old) codebases to put into context the kind of maintainability issues I am discussing, and why my perspective is what it is.

Re:High-performance .NET by example: Filtering bot traffic by osd on Monday April 24, 2017 @05:16PM (#14188377)
It's not a personal attack because I don't actually know anything about you, and I'm not claiming to. I'm making that statement in regard to your two posts up the chain. They are statements that don't reveal any solid, usable points other than to say "simpler code is easier to understand, sometimes performance doesn't matter as much" but in such a strong form as to suggest that the advice plays out a lot in the real world. It doesn't.
Re:High-performance .NET by example: Filtering bot traffic by abiox on Tuesday April 25, 2017 @12:49PM (#14195409)
> ..as to suggest that the advice plays out a lot in the real world. It doesn't.

what makes you say that?

Re:High-performance .NET by example: Filtering bot traffic by hdhzy on Monday April 24, 2017 @03:36PM (#14187356)
Well I don't think the author advises to go all the way down with your code but rather shows how to do that if you want to. As usual - what will anyone do with that knowledge is up to them but you surely will not advise not using a tool because you can do bad things with it.
Re:High-performance .NET by example: Filtering bot traffic by alexandrnikitin on Monday April 24, 2017 @12:59PM (#14185919)
I agree with you, usually you shouldn't optimize to the point when code quality starts suffer. It's all about trade offs. If you have one or two hundred servers and millions of RPS then it could be reasonable. Or coming back to the code quality, perhaps it's worth to re-visit the efficiency part and find another algorithm/ approach (someone suggested FSM in comments in this case)
Re:High-performance .NET by example: Filtering bot traffic by manigandham on Tuesday April 25, 2017 @05:28PM (#14198226)
> Plus programmers are expensive. Hardware is cheap.

This is entirely a matter of scale. 1 dev can make faster software that runs on thousands of machines with far more ROI than the hours they spent. This is common in several industries.