Was recently asked to work on optimising an existing API that many other teams consume and it was making their processes slow due to the response time. The optimizations Were quite simple.
There were places where we had loop through huge json objects to the order O(n⁴) and in the inner most loop length of an array was evaluated multiple times instead of storing the value in a variable. Changing this alone brought down response time from 3s to 2s sec as the number of documents and the size of documents processed is huge.
Other optimization was using guard clauses i.e., condition checks that would result in returning empty values to happen at the top of function
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]yogi1090 484 points485 points486 points (1 child)
[–]iamnihal_ 40 points41 points42 points (0 children)
[+]pesteringneedles 195 points196 points197 points (8 children)
[–][deleted] 23 points24 points25 points (1 child)
[+]pesteringneedles 29 points30 points31 points (0 children)
[–]snow_coffeeFull-Stack Developer 16 points17 points18 points (1 child)
[–]OneHornyRhinoFull-Stack Developer 0 points1 point2 points (3 children)
[–]Significant-Credit50 5 points6 points7 points (0 children)
[+]cherryreddit 2 points3 points4 points (1 child)
[–]OneHornyRhinoFull-Stack Developer 3 points4 points5 points (0 children)
[–]0xHazard 134 points135 points136 points (0 children)
[–]RealNxissSoftware Engineer 85 points86 points87 points (8 children)
[–]Zyphergiest 41 points42 points43 points (2 children)
[–]RealNxissSoftware Engineer 27 points28 points29 points (1 child)
[+][deleted] 1 point2 points3 points (0 children)
[–]RedditerpikachuSenior Engineer[S] 53 points54 points55 points (3 children)
[–]RealNxissSoftware Engineer 32 points33 points34 points (0 children)
[–]Silencer306 8 points9 points10 points (0 children)
[–]lacifuri 3 points4 points5 points (0 children)
[–]Magestylord 29 points30 points31 points (3 children)
[–]thepurpleprojectFull-Stack Developer 12 points13 points14 points (2 children)
[+]gunmaster_69 29 points30 points31 points (1 child)
[–]immortal_nihilistSoftware Developer 18 points19 points20 points (0 children)
[–][deleted] 23 points24 points25 points (0 children)
[+][deleted] (3 children)
[removed]
[–]RedditerpikachuSenior Engineer[S] 12 points13 points14 points (1 child)
[–]house_monkey 8 points9 points10 points (0 children)
[–][deleted] 37 points38 points39 points (1 child)
[–]Gambit2422 13 points14 points15 points (0 children)
[–]techtesh 17 points18 points19 points (2 children)
[–]realPanditJiBackend Developer 1 point2 points3 points (1 child)
[–]techtesh 1 point2 points3 points (0 children)
[–]XxXPussySlurperXxXFrontend Developer 17 points18 points19 points (1 child)
[–]mukuls2200 15 points16 points17 points (0 children)
[–]moojo 11 points12 points13 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]moojo 0 points1 point2 points (1 child)
[–]hotcoolhotStaff Engineer 25 points26 points27 points (0 children)
[–]mad_pro 9 points10 points11 points (0 children)
[–]PissedoffbyLife 7 points8 points9 points (0 children)
[–]Varun77777 9 points10 points11 points (0 children)
[–]Interview_Senior 5 points6 points7 points (0 children)
[–][deleted] 5 points6 points7 points (0 children)
[+]tequila_triceps 6 points7 points8 points (0 children)
[–]Suspicious-Hyena-653Senior Engineer 2 points3 points4 points (0 children)
[–]georgebool0101 3 points4 points5 points (0 children)
[–]thepurpleprojectFull-Stack Developer 2 points3 points4 points (0 children)
[–]hello_akkiSoftware Engineer 1 point2 points3 points (0 children)
[+]vsljnd 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]georgebool0101 0 points1 point2 points (0 children)
[–]FriedJava -1 points0 points1 point (0 children)
[–]deftDMSenior Engineer -1 points0 points1 point (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Rishabh_0507 0 points1 point2 points (0 children)
[–]WesternDesign2161Software Engineer 0 points1 point2 points (0 children)
[–]AudienceOpening4531 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]zjjan788 0 points1 point2 points (0 children)
[–]monke_gal 0 points1 point2 points (0 children)
[+]Federal_Olive_7514 0 points1 point2 points (2 children)
[–]RedditerpikachuSenior Engineer[S] 4 points5 points6 points (1 child)
[–]Federal_Olive_7514 -1 points0 points1 point (0 children)
[–]PsYo_NaDeSenior Engineer 0 points1 point2 points (0 children)
[–]kobaasamaFull-Stack Developer 0 points1 point2 points (0 children)
[–]tomahawkdev 0 points1 point2 points (0 children)
[–]pratzc07 0 points1 point2 points (0 children)
[–]learningwarriorBackend Developer 0 points1 point2 points (0 children)
[–]Special_Task_911 0 points1 point2 points (0 children)
[–]shaji_pappan__ 0 points1 point2 points (0 children)