Performance: Do it less or find another way
One thing that we tried to avoid on the project that I’ve been working on is making use of C# expressions trees in production code.
We found that the areas of the code where we compiled these expressions trees frequently showed up as being the least performant areas of the code base when run through a performance profiler.
In a discussion about the ways to improve the performance of an application Christian pointed out that once we’ve identified the area for improvement there are two ways to do this:
-
Do it less
-
Find another way to do it
We were able to find another way to achieve what we wanted without using them and we favoured this approach because it was much easier to do,
An alternative would have been to cache the compilation of the expression so that it wouldn’t happen every single time a request passed through that code path.
A lot of the time it seems like it’s actually possible to just do something less frequently rather than changing our approach…
For example:
-
Caching a HTTP response so that not every request has to go all the way to the server.
-
Grouping together database inserts into a bulk query rather than executing each one individually.
-
and most of the time this would probably be a simpler way to solve our problem.
-
I quite like this heuristic for looking at performance problems but I haven’t done a lot of work in this area so I’d be interested in hearing other approaches as well.
About the author
I'm currently working on short form content at ClickHouse. I publish short 5 minute videos showing how to solve data problems on YouTube @LearnDataWithMark. I previously worked on graph analytics at Neo4j, where I also co-authored the O'Reilly Graph Algorithms Book with Amy Hodler.