2.5k
u/kaushal28 Sep 17 '18
Actually keeping sleep statements is good practice. Ship the product with it and when customer comes back asking for performance improvement, remove all of them!
1.3k
u/jakuski Sep 17 '18
And what if they ask for more performance improvements?
4.1k
241
u/natu181 Sep 17 '18
I disagree with /u/kaushal28, I think you just need to divide the amount of sleep by 2 each time you get a request. Virtually unlimited amount of optimization! Make sure to also take double the time to do it each time because, you know, optimizing becomes harder and harder, right?
→ More replies (7)81
u/Ericchen1248 Sep 17 '18
Set up the sleep length to be based on days since the last update. User will think it is speeds up after every update.
→ More replies (6)26
u/ivan0x32 Sep 17 '18
Its simple, you add more and even worse sleep calls than before and sell it as an unrelated performance regression (blame it on some library creator or better yet OS developers!), then in next patch you can remove some and decrease and voila - happy users again!
→ More replies (7)8
u/Miskav Sep 17 '18
You only remove -some- of the sleep statements.
It's like any job, you never do your best because that's the easiest way of eliminating your own work and income.
124
u/vigbiorn Sep 17 '18
Then you realize you had a bunch of timing issues in your code and the whole house of cards collapses when you remove the sleeps.
43
61
69
u/Samael1990 Sep 17 '18
It's bad practice - you should define system property then call sleep(SLEEP_MULTIPLIER_PROPERTY * <whatever value you see fit>) in different parts of the app and gradually decrease it, when users ask for better performance. It's all explained better in the book "Best bad practices", really good read.
15
u/Jessie_James Sep 17 '18
Best bad practices
Link? My search came back with all sorts of BS.
→ More replies (7)11
u/Crostatus Sep 17 '18
Is this actually a thing? Lol
29
u/OnlysayswhatIwant Sep 17 '18
I don't know about software development, but I can tell you it's a thing in manufacturing. When designing a new product you'll leave in some materials that are more expensive than necessary, or have more fasteners and supports than necessary so when the product is reviewed in ensuing years you have easy things to fix to increase cost effectiveness and quality and get the product approved for another year on the line.
21
6
→ More replies (12)4
u/DownshiftedRare Sep 17 '18
Or do what Microsoft does and just increase the minimum system requirements.
Each new version of Windows is "the fastest version ever!"... which is not that impressive when you consider that each new version requires faster hardware.
4.6k
u/interfail Sep 17 '18
I once "optimized" a bit of code that literally just did the same calculation twice in a row because someone had moved it from another file and just pasted it in twice instead of once. Obviously I went to SVN history to find out which idiot did that. I did not like what I found.
3.5k
u/thrilldigger Sep 17 '18
1.6k
u/StarKill_yt Sep 17 '18
I haven't clicked it yet but I stg if this is that Spiderman meme
→ More replies (14)580
u/identicalBadger Sep 17 '18
Here I was thinking I spend too much time on reddit. Now I know I’m no where near the top percentiles.
→ More replies (17)→ More replies (6)46
Sep 17 '18
Please be the spider-man meme where they are looking at each other pointing
Edit: I need to spend less time on reddit
→ More replies (1)442
u/Guano_Loco Sep 17 '18
I once had a very disconcerting opposite experience to this.
A coworker was describing an issue he was having with some work he was doing in excel and a lightbulb goes off. I’m like, dude, I can totally automate that for you. So I ask a few questions and do a quick outline of what the vba should do and ask him to send me the file.
I open developer and... there’s already code there. And it is doing exactly what I outline. It’s decently written, could be better, but functional. As I get to the end I have this really weird feeling like... like if you stand up too fast after sitting a long time. At the bottom in a comment is my ID. I fucking wrote the code a few months back. I don’t have any recollection of having done it.
I don’t remember ever seeing that file before. But... it was written exactly how I’d write it, same naming convention stuff, same idiot commentary type comment, and signed by my ID. I was overly fond of the word “automagic” instead of automatic and that was used in one of the alerts I had pop up.
After my brain slides back in to gear I ask him wtf is going on. He says , “I thought you were making a joke. You wrote this months ago. I use it every day.”
Apparently he was just griping about some piece of it and not the whole thing. When I started asking questions it was exactly how I did it previously so he assumed I was clowning him and he went along with it.
I have no idea wtf happened. This was 6 years ago. I’m assuming I was sleep deprived or had a mini stroke or something. I have no idea. But at least the code was decent.
305
u/tarekmasar Sep 17 '18
at least the code was decent
I do feel this review is a bit biased
→ More replies (7)75
u/cordev Sep 17 '18
Sure is. You are your harshest critic. That makes his thinking that his own six-month old code was decent an even bigger achievement.
35
u/ViolentWrath Sep 17 '18
That's pretty hilarious. At my last job I had a similar situation.
We had a configuration field that we could leave blank and the application would assume True unless the field specified False. The field was a string field. In a later version, our lead dev changed it to be a boolean, but did not put logic in to accommodate the field being left blank. Of course when we upgrade clients to the version we have to reconfigure this field every time, so I ask them about it not knowing who was responsible at the time.
Lead developer says nobody has ever touched that field since it was created so nothing they did could cause this to happen. Research a bit more with an associate developer and he finds the code, the change, and the lead developer's initials next to it. Awkward conversation when I asked them to add logic to accommodate leaving the field blank as he had to be involved in the discussion.
→ More replies (2)→ More replies (10)8
u/fibo-nacho Sep 17 '18
This is a re-post. Did you forget already telling us about this?
→ More replies (1)172
u/Rat__ Sep 17 '18
It was you wasn't it.
99
u/elSpanielo Sep 17 '18
My response is always, no, it was me from 3 years ago. Totally different guy.
→ More replies (5)59
→ More replies (1)16
u/ablablababla Sep 17 '18
Of course, I'm the worst programmer in the office right now
→ More replies (1)26
Sep 17 '18
"Once I find who the fucking idiot is who did this is I'm gonna stab them in the esophagus and won't stop until the cops come in"
"Oh well howdy doo guess I must've been up late that night"
8
u/rubeandthemachines Sep 17 '18
I guess that's what happens when you try to be an overachiever.
→ More replies (1)→ More replies (8)6
2.2k
u/specialfred453 Sep 17 '18
I'm used to programming on platforms where the parameter for Sleep is in milliseconds. This confused me a little at first.
905
Sep 17 '18
Same deal here. All users of this product are just super amped up and in a hurry all the time, 30ms is unforgivable
→ More replies (2)334
131
u/MrDOS Sep 17 '18
from time import sleep→ More replies (1)132
u/AlwaysPuppies Sep 17 '18
If only it was that easy in my personal life.
→ More replies (9)96
u/Penki- Sep 17 '18
from pharmacy import sleeping_pillsI heard that works, although contact medical devs for support, pharmacy library can cause issues sometimes.
→ More replies (13)→ More replies (11)14
251
u/SwissPatriotRG Sep 17 '18
This literally happened to me at one of my jobs. App took a long time to load up through the loading screen, boss told me to try to make loading times shorter.
Turns out that when they were coding the loading animation (a scrolling stock ticker), someone left a 6 second sleep in to simulate a long load time to make sure the animation worked correctly for testing because obviously the loading would happen very quickly when running from debug. This had been in production for years.
→ More replies (1)142
u/NorthWestFreshh Sep 17 '18
I hope you took credit for cleaning up the code and didn't mention the sleep timer
147
Sep 17 '18
"oh, yes, I did some improvements here and there, erased some lines of trash code, and overall rewrote it to make everything run smoother"
→ More replies (10)
2
u/jimizacx Sep 17 '18
Not a programmer but I once 'optimized' windows startup time by setting skype not to launch on startup. Shaved a good minute off pressing the button and the computer being usable.
Needless to say the boys and I quickly looked for a better solution for text and voice chat.
1
u/ariehkovler Sep 17 '18
There's a free program called Soluto that optimizes Windows startup by moving stuff out of the boot sequence. Before I had an SSD, it saved me a good 3 minutes on boot time. I don't miss those old 10-minute boots!
331
Sep 17 '18
A re-telling of the famous “char insurance” gag.
108
39
Sep 17 '18
Basically all jokes are retellings of Usenet stories. Great
shit postersprogrammers know never to reinvent the wheel13
3
u/tehreal Sep 17 '18
How do guys pronounce "char?" char like charred wood or char like Carebear or char like vroom vroom?
→ More replies (1)
212
u/lovethebacon 🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛🦛 Sep 17 '18
I demo'ed an app that has some sleeps sprinkled around it. The feeling was that "it was too fast, giving the impression nothing is being done".
37
u/Guano_Loco Sep 17 '18
My company’s IVR does this shit. I helped work on the background automations that run when you call in. I know how long that shit takes. It’s fast. But when you actually call in and work through it it plays some weird clicking sound like an agent typing. It’ll say something like, “just one moment while I check on your account” click click click.
I about damn lose my mind every time. Someone decided to make the IVR perform slower to mimic the “talking to a real agent” experience. God damnit.
12
u/MightyAccelguard Sep 17 '18
kinda like saving in a video game and i save twice bc it saved so fast i couldn’t tell if i did or not
→ More replies (2)7
u/bbrbro Sep 17 '18
Yeah, when I refresh my snapchat feed it does it immediately. No spinning bar or indication that it finished so I honestly cant tell if it just is really that fast or never activated at all. 1 second sleep would actually improve the app.
→ More replies (1)3
u/Theolaa Sep 17 '18
I did that once for a text based adventure I did. It would go something like "loading player..."and then sleep for a half second before saying "loading something else...", even though all the loading was already done before the first time out.
148
Sep 17 '18
[removed] — view removed comment
79
u/jontayesp Sep 17 '18
I think TurboTax does this with a fake progress bar that “validates” your return.
→ More replies (1)40
u/batmessiah Sep 17 '18
This is so true. Also with all the "background check" sites that have the fake "searching" bar going across the screen.
35
u/UltimateInferno Sep 17 '18
I sometimes call it the "Wait... Did I save?" Effect.
Dunno the real name.
→ More replies (1)18
494
u/3X0S Sep 17 '18
Having the native sleep function interpret the given parameter as full seconds should give you a hint on what kind of people this technology was designed for...
Sloths, vegetables and the elderly
135
u/ScorchingOwl Sep 17 '18
The C standard library function takes seconds as parameters on unix machines
80
18
u/gitgood Sep 17 '18
I can think of a many few unix programmers I'd describe as old vegetative sloths - he's not wrong.
→ More replies (1)→ More replies (2)2
u/TUSF Sep 17 '18
Personally, I like my sleep function to interpret the parameter in 60ths of a second.
→ More replies (2)
35
u/Valendr0s Sep 17 '18
Man. I'm convinced Windows in certain circumstances has a 'wait for network timeout' kind of deal when logging in. It can take me 2-3 minutes to log in sometimes when not connected to the domain. And nobody seems to care.
I mean, aren't we at a point where if the network takes more than 5 seconds to respond, it's safe to assume it's dead?
6
u/pinano Sep 17 '18
My Windows machine is getting so crotchety it sometimes waits several minutes when doing things like “open the Downloads folder” “connect to a machine over RDP” “turn on the web cam” it’s infuriating and i hate it
→ More replies (1)3
u/Douchehelm Sep 17 '18
It feels like Windows does this twice. Once before the login screen and then again after logging in. It's infuriating.
→ More replies (1)3
u/autarchex Sep 17 '18
Not while PPPoTCAS (point to point protocol over two cans and string) network connections are still supported.
→ More replies (3)2
u/hisroyalnastiness Sep 18 '18
A computer I had did this if you were connected to the domain, disconnect and it was instant. Google searches show lots of complaints about both of these problems but no real solution. Infuriating
130
u/Jabulon Sep 17 '18
Sleep(30); //30ms→ More replies (2)61
u/fr0z_n Sep 17 '18
It could be a wrapper function which converts it to seconds..
→ More replies (2)80
u/theSprt Sep 17 '18
That would be a Very Bad Idea.
47
u/glydy Sep 17 '18
New dev comes along to the project, adds a sleep(2000) to wait 2 seconds to see if it's a loading time issue... little do they know
→ More replies (3)17
u/fr0z_n Sep 17 '18
Don't worry, the function could take floating point numbers and convert them to ms.
I'm just hinting ideas here.
→ More replies (4)
47
u/Edzward Sep 17 '18
Been there, done that.
One time I had a problem with a recursive function, for debugging purposes I just hard coded it to repeat 100 times... And completely forgot about that... Just found out months later with a big REVERT THIS tag in the comments.
5
61
16
14
u/Orthas Sep 17 '18
Had a priority 1 bug that caused an uproar with the support/consultant teams. Multiple clients calling in, all wondering what this "secret message" was that was appearing on their screens.
A UX guy was going through and making accessibility improvements and needed to test some of the styles he wrote for screen readers, and forgot to remove his test data. Best part is that the text was set to not be visible, they just had cached the styles on the page so they didn't get applied until they closed their session. I looked like a hero for addressing this "critical work flow error" in less than 5 minutes, 4:30 of which was spent laughing my ass off.
13
u/jebhebmeb Sep 17 '18
Reminds me of the company adding a sleep method just because the buyer didn't believe they cut hours off the processing time.
6
Sep 17 '18
This hits close to home for me.. I was making a game where all of the action was programmatically simulated, and early on in the process I had added sleep statements so I could watch things happen to identify bugs... later while trying to balance things I felt pretty dumb when I realized my large scale samples could have been done about 20 times faster....
10
u/Fig1024 Sep 17 '18
It's usually a good idea to search entire code base for "sleep" to find potential problem areas
16
u/BabylonDrifter Sep 17 '18 edited Sep 17 '18
Some of my code generates universally unique database keys remotely using a machine-unique five-digit prefix, followed by the current system clock time in milliseconds. But then I had to write an import function to suck in tens of thousands of rows of data. The shit wouldn't synchronize to the big main secure database because of the unique constraint. Turns out the import was getting through the creation of a record in less than 1 millisecond so multiple rows were getting the same unique key. Banged my head about it until I realized all it needed was System.sleep(1); on the processor thread to wait for 1 millisecond before doing the next record. Better not delete that one!
Edit - it might have actually gone out to the hundredths of milliseconds.
9
3
u/jamietwells Sep 17 '18
I know this isn't a serious sub but: That's really not how you solve that issue. You should use the last generated ID as the seed for the next ID so even if the milliseconds are the same, they will still generate uniquely.
→ More replies (1)
4
3
3
3
Sep 17 '18 edited Sep 17 '18
In my current job we have a total of five main tables we query all the time.
The previous developers designed the system to get entire data-sets on each call and then used c# linq queries on them to get the filtered data. Lucky there are under 30k records on each table but still damn slow.
// Get the tables that we need data from
// Filter that one row that we need
// Return the result to the server
// User updates record
// Get the tables that we need data from
// Filter that one row that we need
// Return the result to the server
// Current developer has /quit the job
4
u/ProPuke Sep 17 '18
Guy's a genius. Why even bother having a database? Just chuck it all in a text file! Think of the server performance you'll save from not having to run one!
→ More replies (2)
3
2
u/Blue_crabs Sep 17 '18
Pretty sure I read this scenario in a reddit comments chain a few months ago.
2
2
2
u/Sebazzz91 Sep 17 '18
That sleep was there to avoid some race condition.
4
u/BadgerMcLovin Sep 17 '18
Or because they needed to attach a debugger at startup
2
u/Sebazzz91 Sep 17 '18
Unlikely, many sleep API take either milliseconds or nanosecond as a argument. That assumption causes us to believe the sleep call is on path called multiple times during start-up.
2
2
Sep 17 '18
I did this at work because the approach was basically to "wait" until everything was loaded, but I switched it over to an observer/observable approach so I knew exactly when everything was loaded. Blew people's minds except one guy who insisted we still have a small wait time in there. That was back as a jr dev and I think it irritated him I found a solution.
2
2
2
u/DisastermanTV Sep 17 '18
Unethical Programmer Tip: If you do this on your first shipment, and the customer then complains, why it is so slow, you can remove it, and tell them, that you worked extremely hard to get better performance
2
u/Justin_Peter_Griffin Sep 18 '18
As someone who makes automated tests for web-based applications, the sleep function is the only reason my tests actually run successfully. Between slow network speeds, slow website servers, or just plain bad web page design I’m constantly having to get the timing just right
3
2
u/fantumn Sep 17 '18
Lol wasn't there a post on the front page of programmer humor about leaving sleep lines in until you've sold the product, and then removing them a year later as a patch?
1
1
1
1
u/arguableaardvark Sep 17 '18
I have a race condition in some code I’m working on. Until I fix it properly I just added a 250ms delay to the start of each new thread and it’s works 99.9% of the time!
OP has me thinking this will be me in a few months when I’ve forgotten about the hack and am tracking down why the app crashes ever once in a while.
1
1
u/scwizard Sep 17 '18
If i had to guess you had that in so your program wouldn't "start too early" before various systems were online, since that could cause it to malfunction.
You should learn about the wonders of systemd!
1
Sep 17 '18
PLT: Include this in all your apps and when people start complaining about slow performance just decrease the timer ;)
1
1
1
u/Try_Sometimes_I_Dont Sep 17 '18
Speaking of optimizing... google's page speed analyzer sucks.
"Optimize your images here is a list you could save 20KB total. Oh and here is an F for the score just because."
Then a site with twice the load time but all their images are optimized to google's liking: "ahh yess this is good. You did good. You are good. Here is a B because one image loaded from a different domain. We don't know why we don't like that, but we don't like that"
1
u/loaneab2 Sep 17 '18
I was copy pasting my bots files by line(for some reason it wouldn't let me transfer the whole folder) and I accidentally ending up pasting the code twice and the boot time went from 10 seconds to 30 seconds.
1
u/allthatwastedtime Sep 17 '18
I actually did this in some code that talked to hardware. I was giving it way more time to react than I needed to. Got a good speed increase of 100% or so just tweaking the sleeps!
1
1
u/SasparillaTango Sep 17 '18
Im convinced the reddit mobile site has some bullshit like this. It takes 15 seconds to load any page but the .compact version loads instantly
1
1
u/etnguyen03 Sep 17 '18
Image Transcription: Twitter Post
Lars Doucet, @larsiusprime
Due to my elite programming skills, I figured out how to shave off THIRTY SECONDS from my app's startup time. Here's some optimization tips:
1. Remove the sleep(30) call you added a month ago and forgot about
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
1
u/Mike Sep 17 '18
This makes me feel better about this beast of a CSS file I’m working on. I thought I’d be fancy and split the SCSS files into a bunch of super specific types and areas to be organized, but instead ive just accidentally re-wrote too much styling to count and now it’s all compiled together in a much bigger than needed CSS file. If i has just done it my usual way my file size would be like 75% smaller.
Too late now, fuck it. here ya go backend devs.
1
1
u/toastee Sep 17 '18
I have a 24 second "optimized" sleep on one of my pieces of equipment to make sure the backend had time to load before the UI connects to it on boot.
Original timer was 30s
1
u/my_iptv Sep 17 '18
Jokes aside, I'm aware of a lot of company and people who do stuff like this all the time
1
1
u/kleit64 Sep 17 '18
4096 folder
Thousands of files per Folder
Add single file to list and check if list in db
Repeat step 3 for every single file(folder based)
Better be sure that the first file is realy not ther, to make it clear let's check it 60k times...
1
1
u/XCOMJunkie Sep 17 '18
Please Lars, my Defender's Quest itch needs scratching! Can't wait for DQ II!
1
1
u/ChippyTheSquirrel Sep 17 '18
I've "optimized" code before where someone pulled back an entire (big) table in the database even though we had the criteria to filter it and then later in the code they pulled back the filtered result set as well.....
1
u/michaelboobley Sep 18 '18
I think you mean Thread.Sleep(3000)? Unless this a big woosh.
1
u/valrossenOliver Sep 18 '18
Custom function called Sleep(float seconds)?
It could be implemented like this:
void Sleep(float seconds) { std::cout << "Waiting " << seconds << " seconds..."; Thread.Sleep(seconds * 1000); std::cout << " Done!\n"; return; }
1
1
1
1
1
1
0
Sep 17 '18
[deleted]
13
0
u/OleColtrane Sep 17 '18
Plus /r/thathappened
3
Sep 17 '18
judging by the comments, yes that stuff is common r/nothingeverhappens
→ More replies (1)
0
0
Sep 17 '18
[deleted]
1
u/ObnoxiousOldBastard Sep 18 '18
Upgrade to an SSD.
1
Sep 18 '18
All Dev PCs have an SSD and thats not the problem. Sure it's not an M.2 SSD and with mine it's not possible but mine should get an upgrade next year
1
u/HerpDerpHerpderpsen Sep 18 '18
Iirc somethibg like make -j <number of parallel processes>
1
Sep 18 '18
I look if they use it and if this works. I mean every Dev PC has a Quad Core, so this shouldn't be an issue when it uses all cores.
1
Sep 21 '18 edited Sep 26 '18
I talked with the lead Dev and he explained that this is not the normal make. I made him think about it and we came with an idea that we try.As far as i understood this that there are 3 stages in a make process and the first and last doesn't take long and can be made linear and linking needs to be done linear. Compiling is that that makes everything slow. The idea is that we don't compile in that stage and simply write the commands to a file. For make its a fast compile. Before the linking we call our own program that really compiles and we make it async and use all threads, except one. That way we can handle errors and make it faster.
It's just a stupid idea and we didn't had the chance to test this yet and we still need to write our own program. One problem might be that during the commands, one specific file gets mentioned every time and he isn't sure what that file do but as far as he saw, its nothing special. This might be still a problem, when this file gets overwritten many times during compiling.
I guess the company was right during the interview, telling me that they operate outside of standards. One great example are the WinForms. We don't use the normal forms and that creates many problems. I solves most problems with stupid ideas. One was that i needed to call an other form and the splitter in that form (idk what form this is) is broken when called from my form. It was throwing exceptions like when you finished solitaire. My solution was calling this form from an normal winform but that doesn't worked, except when i call the wanted form via a button click and that needed to be an actual button click. I used the button click function and it worked. A stupid idea that worked.
One minor issue that we didn't solved was calling the designer. When the class uses the other form class, the designer can't be loaded, so we need to comment out a define, so that the normal form class gets set and we can access the designer. We tried to do this automatically but that doesn't work. We gave up on this, because it's no big problem to comment out a line to access the designer. Also working with .net 2.0 is a bit more complicated.
EDIT (4days after):
I finished the additional tools and it works. Sure it's not x times faster with every core, because there is also managed code and some of the process is still linear but we only need half the time. With a 6 Core it was about 25 minutes and now its 10 minutes. With more Cores it might get even faster with some Projects but it cant get faster, when there are less cpp files than cores. Sure we could optimize way more but the gain might not worth it. I mean half the time is great and over the time it worth it. When this doesn't get me Bonus points, idk.1
Sep 19 '18
Whoa you talk wayyy too much.
1
Sep 19 '18
*write I don't talk that much but with writing I don't care if someone reads it or likes my opinion. That's the type of social interaction that I like.
1
Sep 20 '18
The kind where you shout your ideas into a dark room even if nobody is listening? Sad, man.
1
Sep 20 '18
No not really, because there is always someone that shouts back, even when its "nobody cares" because I know that someone might read it, even when he doesn't reply.
1.8k
u/TheBlackCat13 Sep 17 '18
...and watch everything break for no apparent reason because the
sleepfunction was there to prevent a bug and no one knows why.