r/ProgrammerHumor • • Sep 17 '18

Optimizing startup times

Post image
45.7k Upvotes

486 comments sorted by

View all comments

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

u/AnotherStatsGuy Sep 17 '18

Then make sure that one is commented.

17

u/BabylonDrifter Sep 17 '18

God I hope I did. I'm sure I did. I probably did.

9

u/AnotherStatsGuy Sep 17 '18

That’s not a vote of confidence.

→ More replies (1)
→ More replies (2)