3 Techniques to help you optimize your code bases[Technique Tuesdays]
One of these techniques covered could have saved over 450 Million Dollars.
Hey, it’s your favorite cult leader here 🐱👤
On Tuesdays, I will cover problem-solving techniques that show up in software engineering, computer science, and Leetcode Style Questions📚📚📝📝.
To get access to all my articles and support my crippling chocolate milk addiction, consider subscribing if you haven’t already!
p.s. you can learn more about the paid plan here.
As developers/managers, we all know how important it is to write code that zooms past efficiently. It’s why computing the O-complexity of your run-time and space are given so much importance. Read any major engineering blog, and you will see that most of the challenges faced relate to scalability and safety. So computationally-efficient code is a must. But how do you achieve that? In today’s newsletter, I will share with you three techniques for optimizing your code to help you build better software systems. Pay attention to these, because one of these techniques could have saved a stock trading company from bankruptcy.
3 Techniques for code efficiency 🚀🚀🚀
Compile time evaluation- Compile time evaluation is the ability of a compiler to execute a function or an expression at compile time rather than run time. This is possible if the arguments to the function or the expression are known at compile time, and the function does not make any reference to or attempt to modify any global state (i.e. it is a pure function). This can save you some memory and CPU time at run time, as well as catch some errors early. The speed advantage of compile time execution is discussed in this Software Engineering Stack Exchange Discussion.
Dead code elimination- Dead code elimination is the process of removing code that is never executed or has no effect on the program’s output. For example, if a variable is declared but never used, or if a branch of an if statement is always false, then that code can be eliminated. Dead code elimination can reduce the size of your executable and improve your code’s readability and maintainability.
When the New York Stock Exchange opened on the morning of 1st August 2012, Knight Capital Group’s newly updated high-speed algorithmic router incorrectly generated orders that flooded the market with trades. About 45 minutes and 400 million shares later, they succeeded in taking the system offline. When the dust settled, they had effectively lost over $10 million per minute.
Some compilers can perform dead code elimination automatically as part of their optimization passes, but you can also help them by using static analysis tools or code coverage tools to identify and remove dead code. Also keep in mind, compilers themselves might add more dead-code in your systems. Thus, it is important that you’re always running dead-code elimination. This also has the added benefit of improving code readability and quality, which can be an equally strong advantage.
Strength reduction- In compiler construction, strength reduction is a compiler optimization where expensive operations are replaced with equivalent but less expensive operations (credit- Wikipedia). This can be a great avenue for investigation when it comes to optimizing code bases since strength reductions tend to be the most localized (limited to a certain section of your code) out of the techniques discussed today. So making changes is a lot easier.
These are just some of the techniques for optimizing your code that you can use to improve your skills and productivity as a developer. Of course, there are many more techniques and tools that you can explore and learn from. But remember, optimization is not an end in itself. It is a means to achieve better quality, reliability, and usability of your software.
That is it for this piece. I appreciate your time. As always, if you’re interested in reaching out to me or checking out my other work, links will be at the end of this email/post. If you like my writing, I would really appreciate an anonymous testimonial. You can drop it here. And if you found value in this write-up, I would appreciate you sharing it with more people. It is word-of-mouth referrals like yours that help me grow.
Upgrade your tech career with a premium subscription ‘Tech Made Simple’! Stay ahead of the curve in AI, software engineering, and tech industry with expert insights, tips, and resources. 20% off for new subscribers by clicking this link. Subscribe now and simplify your tech journey!
Using this discount will drop the prices-
800 INR (10 USD) → 640 INR (8 USD) per Month
8000 INR (100 USD) → 6400INR (80 USD) per year
Reach out to me
Use the links below to check out my other content, learn more about tutoring, reach out to me about projects, or just to say hi.
If you like my writing, I would really appreciate an anonymous testimonial. You can drop it here.
To help me understand you fill out this survey (anonymous)
Small Snippets about Tech, AI and Machine Learning over here
Check out my other articles on Medium. : https://rb.gy/zn1aiu
My YouTube: https://rb.gy/88iwdd
Reach out to me on LinkedIn. Let’s connect: https://rb.gy/m5ok2y
My Instagram: https://rb.gy/gmvuy9
My Twitter: https://twitter.com/Machine01776819