Modification, Improvement: Code Optimization and Scalability

Nabila Khansa
3 min readMay 12, 2022

--

When developing a program, we tend to test its acceptance on a smaller scale, forgetting that on a larger scale it might not run as smoothly despite being functionally correct.

What is Scalability?

Something is called scalable when it works similarly at a larger scale as it does on a small scale. If it takes a minute for me to read a paragraph but an hour for me to read a book, that means I am not scalable. Also, if a scanner scans a page in a minute and a book in two minutes, that suggests the scanner is more scalable than I am. The ability of a software to scale is referred to as scalability, a highly scalable software would operate well on both a small and a large collection.

Code Optimization

Optimization is the process of making something that already exists more efficient while performing the same tasks. This can mean that the same operation will take less time to process, a reduction in the amount of memory required, or simply that less disk space is required. Making trade-offs, such as requiring more memory in exchange for faster processing, is a common part of optimization.

Scalability and Code Optimization in Badaso LMS

This is an example of a Badaso LMS optimization I performed, optimizing a multiple query function to retrieve needed data in a single query. It’s not perfect, but it’s the best I could do given the time constraints.

Figure 1. Original Code

This was the original code I wrote in the first sprint. Back then I was still a total noob and did not have enough knowledge on the programming language as this is my first project with PHP and Laravel. I brute forced my way to make sure the code works, returning the needed data without bothering about code efficiency. I had no idea how to join tables, so I simply took data from one table, loop that data to get data from another table with what I already had,

Figure 2. Code Review

Obviously, knowing that I made quite a mess, I did not just let it be. I made a refactoring branch to first move the function from CourseUserController to CourseController. In the process, my friend Aldi noticed the smelly code. As he said, the loop weights down heavily on the code performance.

Figure 3. Code Optimization

After hours of fumbling around the internet, I… still could not comprehend the syntax and how to make it make sense. Fortunately for me, my friend Dion is a lot smarter than me and taught me how he did a simple join tables for his code. I improvised on that and came up with this modified version of my original code.

I hope you find this blog helpful, if you find any mistakes or misinformation, I would very much appreciate the feedback. Thank you!

Reference

What does “scalability” mean? Stack Overflow. Retrieved April 12, 2022, from https://stackoverflow.com/questions/9420014/what-does-scalability-mean

Difference between Optimization and Scalability? Stack Overflow. Retrieved April 12, 2022, from https://softwareengineering.stackexchange.com/questions/232487/difference-between-optimization-and-scalability

--

--

No responses yet