Live data from Hacker News

Best practices can slow your application down

stackoverflow.blog

51–60 of 187 posts

Re: Best practices can slow your application down

#51
The article makes the excuse that static (singleton) interfaces are inherently simpler and less resource intensive enough for it to be worth skipping regression testing (because testing that style of code is hard.)

Reading between the lines, it sounds like maybe they know they've dug themselves into a very expensive hole to dig out of. I've jumped head first into codebases that made the same excuse, and to me it seems severely limiting in terms of long term productivity. There are definitely benefits to simple, "static" singleton interfaces, and such interfaces aren't inherently incompatible with mocking and dependency injection. It does mean you likely need a layer of indirection somewhere, but if you're sweating the overhead of a single vtable lookup or explicit function pointer call on code that's internally accessing a non-trivially sized data structure, how are you even able to measure it?

The problem is that a handful of foundational static interfaces never got unit tested, and all the other code calls directly into them, so nobody anywhere wrote any unit tests because they couldn't (without touching foundational code that's unsafe to modify for lack of unit tests.) The first step in the right direction is to fix the foundation. This is terrifying for the folk that have been around a while and cemented in their assumptions about risk because they've tiptoed around modifying portions of the codebase for years. Luckily, a big benefit of static singleton interfaces is that it's very easy to modify them with O(n) developer time (where n is the number of references in the codebase). So, you just have to buckle down and get your hands dirty. You're pretty much guaranteed to find at least one latent bug in any old piece of code that you unit test, and so folk start to see the merits of the test coverage and it becomes easier to prioritize refactoring more and more ancient and scary code. After you've done it to half a dozen or so disjoint pieces of code, something magical happens. Suddenly, the vast majority of the codebase becomes easily unit testable.

Re: Best practices can slow your application down

#52
post #8
post #4

In my opinion, the idea that you can have well-tested code OR performance is tosh. If you don’t have good testing and do it regularly how can you refactor your application for speed if you’re not going to be sure that you’re going to introduce a regression? And I think the stackoverflow team know it: > Currently, we’re trying to change this. We’re actively trying to write more tests and make our code more testable. I…

> This makes it sound like a lofty goal… Sales pitch 101. Sell your weaknesses as strengths.

Also true in interviews. When asked about their weaknesses, some candidates who have thought this through might say something like "I spend too much time trying to help struggling colleagues" or similar.

Re: Best practices can slow your application down

#53
I’m just thinking about how much CO2 emission was spared by optimizing performance instead of scaling horizontally.

It would be nice to see the effect on the environment as part of the decision-making process for deciding whether to optimize versus scale.

I think developers have an innate desire to fix performance issues as optimization produces a better understanding of the code and the problem and developers would like to solve the problem in the best possible way. And it helps to know that the problem won’t bite again later.

Re: Best practices can slow your application down

#54
post #20

Somewhere down the line, developers will start to realize that single applications running in the same server memory and CPU cache will run much faster than Micro services applications that makes api calls over the network. Depending on your organization scale of course, but for many smaller shops, there is a significant performance overhead of going over the network. Ie a Single binary running Rust/Go/Java/NodeJs vs…

Within the same data center, a network call doesn't need to have significant performance overhead; it can be on the order of a read from main memory. Still overhead, but for many SLOs it's irrelevant.

The inherent cost of microservices is conceptual and organizational complexity, not runtime performance (though you can certainly build slow microservices, you can also build slow monoliths).

Re: Best practices can slow your application down

#55
post #25

When I was an SRE-SE I despised the term "best practices". Teams would come in telling me all about the new best practice with serverless, Kubernetes, secrets storage, or whatever. It was almost always like someone took a magnificent full Lego set and snapped off a wall and was like, "Hey, try this, it was useful to us." If it's not a protocol or standard recognized by one of the IEEE, IETF, or ISO then it's a tutori…

I agree. Lately, I try to refrain from using the term 'best practices' in favor of 'good practices', 'common practices' or even 'my practices' for several reasons:

- True best practices mainly refer to standards, and this list is very slowly updated, unlike the number of false ones;

- It's often used for marketing purposes, which works well, but doesn't always imply quality;

- Since this spreads fast, we often have things at the places where they do not fit, but squeezed into, because it's the best, so we must have it;

- Forms a wrong mindset to rely upon someone else's experience instead of learning and gaining own understanding.

In the end, we have tons of inapplicable or controversial information to filter, which doesn't make things better, in my opinion. Sharing is great but we should do it responsibly.

It's also a bit funny to watch how the best practices suddenly become the worst.

Edit: formatting

Re: Best practices can slow your application down

#56
post #5

The argument against Tests sounds like a tooling problem to me. Why shouldn't a compiler be able to optimize the modular approach to the same code that a monolithic approach yields?

Why is that relevant? The fact is that it doesn't (there are good reasons for it, but that is another matter). You can't work with the ideal tools, you can only work with the tools that actually exist. So, with the actual tools, this sacrifice must be made. And now do answer your actual question, the reason is that the languages we use are just not expressive enough, and the compiler doesn't have enough time. If you…

It is relevant because they chose to abandon best practices because of a lack of tooling. A badly chosen language constraining your development methods is like a tail wagging the dog. There are languages and, more importantly, implementations out there that allow this kind of design. Just think of SML/NJ as an example for the principle.

If performance is important and C# doesn't allow unit testing performant code then switch to C++ or Rust.

It is staggering how many people seem to see the choice of language as an absolutely unchangeable decision. Rewriting even millions of lines of js or python code is definitely doable, even incrementally, and if your organization does not deem it worth the effort then maybe performance is not your most important concern.

Re: Best practices can slow your application down

#57

I have to admit I would far rather work on a conceptually simple codebase, that has been kept fast and light with minimal testing, than to work on a conceptually muddled codebase with 100% testing. Performance is a feature, and so is being able to reason through a codebase. Being able to fit all the pieces in your head is a feature, but not so snappy.

> Being able to fit all the pieces in your head is a feature, but not so snappy. How about "architectural sanity is a feature"? It kind of isn't though. Clients don't care about qualities of your code that they can observe. They notice if your code is fast, but don't care it it's easy or hard to reason about. If anything, I'd say it's a bit of a meta-feature, because code-quality is directly linked to many other prop…

yes, but I think we live in a world of increasing software literacy - where a novel or a manifesto that is easy to read will beat out those that are not. Similar for software - the good software will include 'makes sense in the readers head'

Re: Best practices can slow your application down

#58
It sounds like the team is interested in adding more automated tests, but are blocked by static singletons, which have high performance but also high coupling, resulting in poor testability.

I'm sure they've heard of test libraries like MS Fakes and Pose; I wonder if these libraries would let them maintain high performance, and only introduce the required layer of indirection during testing?

Re: Best practices can slow your application down

#59
These sound like some poor excuses to me.

The idea that you can have either best practices or performance is a false dichotomy. Testing can be used to help track down performance issues. It can help you write code faster and prevent breakages. It should not slow you down.

Best practices inside a codebase should not sacrifice performance. If you have to do that to conform to some structural ideal, you don’t do it. I would love to see this supposedly untestable code.

Stackoverflow may contain lots of great dev knowledge, but it’s also a weird site that discourages participation and entrenches old answers. I am unsurprised that the devs themselves are a proverbial old dog that can’t learn new tricks.

Re: Best practices can slow your application down

#60
post #20

Somewhere down the line, developers will start to realize that single applications running in the same server memory and CPU cache will run much faster than Micro services applications that makes api calls over the network. Depending on your organization scale of course, but for many smaller shops, there is a significant performance overhead of going over the network. Ie a Single binary running Rust/Go/Java/NodeJs vs…

I'd like to point out that the article does mention that their system is not single process. They have a database, caching layer and web servers at the very least which could be run on a single box. The number of API calls is a matter of degree when compared with a microservices architecture.

A microservices approach does not mean that they should run on different hosts and an early design decision should be that the entire architecture can run on a single host and that the scale out is a feature of the system.

It's worrying that this assumption is often made because it does lead to the maintenance and velocity issues that teams encounter when naively adopting microservices.

Post reply on HN