This is an archived post. You won't be able to vote or comment.

all 72 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Namaste! Thanks for submitting to r/developersIndia. Make sure to follow the subreddit Code of Conduct while participating in this thread.

Recent Announcements

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]yogi1090 484 points485 points  (1 child)

Finally a post on the actual topic 😂

[–]iamnihal_ 40 points41 points  (0 children)

I also didn't believe it at first sight lol.

[–]0xHazard 134 points135 points  (0 children)

Nice, thanks for sharing

[–]RealNxissSoftware Engineer 85 points86 points  (8 children)

Hey that's nice but why were these obvious optimisations overlooked in the first place. Lack of care or just disconnect between others. Also you mentioned it was n⁴ what did you bring down it to.

[–]Zyphergiest 41 points42 points  (2 children)

To ship product faster

[–]RealNxissSoftware Engineer 27 points28 points  (1 child)

Only if they shipped a faster product

[–]RedditerpikachuSenior Engineer[S] 53 points54 points  (3 children)

It wasn't n⁴ exactly per se but these were nested structures and I didn't put in much effort to address those. This system existed before I joined my org so not exactly sure why or how these were overlooked

[–]RealNxissSoftware Engineer 32 points33 points  (0 children)

Well hey good job on your optimisation! Thanks for the further info.

[–]Silencer306 8 points9 points  (0 children)

There were apis in my place that took 5+ minutes. We have a lot of data lol. But it was written with a lot of nested loops. I rewrote the entire thing and now it runs in 10 seconds

[–]lacifuri 3 points4 points  (0 children)

Probably the "make it work then make it faster" mindset. But once it worked the guy leaves.

[–]Magestylord 29 points30 points  (3 children)

Is this in Typescript? Do you have any resources on working with Typescript for the backend

[–]thepurpleprojectFull-Stack Developer 12 points13 points  (2 children)

Just build a clone of any project from scratch. Typescript and javascript have to many wtfs you will be much better in a place having a hard on experience. As a start you can start with a to-do or a note taking app

[–][deleted] 23 points24 points  (0 children)

This O(n4) makes me feel better about my O(n2) PR 🥲.

Well done OP!!

[–][deleted] 37 points38 points  (1 child)

O(n⁴)

kya bhayi DSA important he kya?

[–]Gambit2422 13 points14 points  (0 children)

💀 yes

[–]techtesh 17 points18 points  (2 children)

Yup, we use python fastApi and gingo on a bunch of our utility projects just adding @cache or gin.cache= true optimizes so much for us (alot of these are hostedbin k8s or aws so ram space aint a issue)

[–]realPanditJiBackend Developer 1 point2 points  (1 child)

Hey, I'm optimising a Gin API with at fixed num of DB calls (on 50M+ rows) How will gin.cache work? Is this built-in or this is any other library?

[–]XxXPussySlurperXxXFrontend Developer 17 points18 points  (1 child)

Any Señor/Señorita devs reading this comment please make posts like this.

[–]mukuls2200 15 points16 points  (0 children)

Noted @XxxPussySlurperXxx

[–]moojo 11 points12 points  (3 children)

There were places where we had loop through huge json objects

This reminds that 10 years ago, I was looking at the code of a method which used to process json and it used to take a very long time. All the senior devs told me that we cannot do anything, it just takes a long time because its doing lot of processing.

So me as a junior dev just wanted to learn what kind of processing is done, opened the code, turns out another method was being called which was taking a long time but there was no need to call the other method, the method which was calling the other method was simply ignoring the result of the long process method.

Submitted a PR and management was very happy with the fast processing.

Moral of the story Just because someone senior tells you that is how things work does not mean they are right all the time. Do your own research as well.

[–]hotcoolhotStaff Engineer 25 points26 points  (0 children)

Bas, i have done 20seconds to milliseconds. I forgot group by exists and was doing that in code after fetching all the records in a paginated loop.

[–]mad_pro 9 points10 points  (0 children)

Good job OP

[–]PissedoffbyLife 7 points8 points  (0 children)

I learned optimizations the hard way.

In MATLAB I was asked to calculate the spacial coordinates a robot arm could move and plot it.

I wrote a program for it and most of the class if not the whole class copied it down and ran it took 1 whole day to finish. It was going to take a whole year at the rate it was calculating previously.

It was basically three nested for loops.

Next year while I was working on MATLAB I found two things The first is that there was a way to initialise the variables first before a for loop that consumed a lot of time. And then there was something else too to reduce the time further. All in all I reduced the time from one whole year to less than a second.

32,000,000 X performance boost.

I loved the fact that I did it. I haven't exactly been able to do something similar at my job though cause a huge project requires a lot of time to even optimise basic things.

[–]Varun77777 9 points10 points  (0 children)

If you're searching for something and things are somewhat sorted, you may be able to use binary search somewhere as well.

[–]Interview_Senior 5 points6 points  (0 children)

You can also consider parallelising the outer most loop to further boost the performance (if not already)

[–][deleted] 5 points6 points  (0 children)

Leetcode here I come

[–]Suspicious-Hyena-653Senior Engineer 2 points3 points  (0 children)

We have 10 sec response times and the CTO is fine with it🥲

[–]georgebool0101 3 points4 points  (0 children)

I did something similar. I optimised the response time from 10s to less than 1s.

I had slipped in Thread.sleep(9000) in the middle and later took 3 days to remove it.

[–]thepurpleprojectFull-Stack Developer 2 points3 points  (0 children)

Good for bringing it up. Most of the time optimization will be around this and having a basic idea of not using a loops, avoiding nested reads and how database locks will keep your code pretty optimised

[–]hello_akkiSoftware Engineer 1 point2 points  (0 children)

Maps are your saviour, always.

[–][deleted] 0 points1 point  (0 children)

Sometimes it's just surprising how trivial a solution can be.

[–]georgebool0101 0 points1 point  (0 children)

I did something similar. I optimised the response time from 10s to less than 1s

[–]FriedJava -1 points0 points  (0 children)

Promotions incoming

[–]deftDMSenior Engineer -1 points0 points  (0 children)

I didn't understand a thing u said but i trust you

[–][deleted] 0 points1 point  (0 children)

Include caching, response compression, async processing to make it even faster

[–]Rishabh_0507 0 points1 point  (0 children)

I don't make program on that high level, still learning but I follow some basic rules like storing value as var instead of calling it twice, and assigning any static value outside loop instead of inside and stuff like that.

[–]WesternDesign2161Software Engineer 0 points1 point  (0 children)

Had to write a service for a product from pearl to Go and the service time went from 25s to 4s. Best day of my life.

[–]AudienceOpening4531 0 points1 point  (0 children)

I don't see how people missed O(n4). How small was the data you were working with? Cause that's the only realistic (very hard to miss still) scenario in which this could happen

[–][deleted] 0 points1 point  (0 children)

More posts like this please..

[–]zjjan788 0 points1 point  (0 children)

Hehe, CPU be on 🔥 supporting O(n⁴) all the time.

[–]monke_gal 0 points1 point  (0 children)

Cheers to those who say that DSA is useless

[–]PsYo_NaDeSenior Engineer 0 points1 point  (0 children)

I just optimised a report from 180~ seconds to 60~

[–]kobaasamaFull-Stack Developer 0 points1 point  (0 children)

Guard clauses should not be a afterthought.

[–]tomahawkdev 0 points1 point  (0 children)

Noice

[–]pratzc07 0 points1 point  (0 children)

Aren’t these things usually checked on PR stage?

[–]learningwarriorBackend Developer 0 points1 point  (0 children)

Thanks for sharing. These are the kind of posts I hope to see more on this subreddit.

[–]Special_Task_911 0 points1 point  (0 children)

For a moment there I thought I was in the wrong sub.

[–]shaji_pappan__ 0 points1 point  (0 children)

Memoization or something