A Creative, if Destructive, Approach to Runtime Optimization
Description
This is a two-part meme format contrasting a technical interview question with a candidate's absurd solution. The top section, labeled 'Interviewer:', asks, 'Can you improve the runtime of this function?'. The middle section, labeled 'Me:', displays a Python code snippet from a file named 'shitpost.py'. The code imports 'Thread', starts a given 'my_function' in a separate thread, and then enters a 'while' loop that calls 'time.sleep(-1)'. The bottom section shows the interviewer's reaction using the 'Outstanding move' meme, which features a man next to a chessboard, sarcastically applauding the move. The technical joke is that passing a negative number to 'time.sleep()' in Python raises an immediate 'ValueError', crashing the main thread. The function's runtime isn't improved at all; the program just terminates instantly, making it seem like the task is done. For experienced engineers, this is a multi-layered joke about interview pressure, lateral thinking, and the critical difference between actual performance optimization and simply making a program stop
Comments
25Comment deleted
My function's runtime is now O(ε), where ε is the time it takes the Python interpreter to process a fatal error. Your move, interviewer
Spawn the work in a thread, call sleep(-1), and watch Prometheus report P99=0 - turns out the fastest algorithm is convincing the metrics pipeline the request never existed
Ah yes, the classic 'negative sleep' optimization - because if sleeping for positive time makes things slower, surely sleeping for negative time will make them faster! Next up: improving database performance by setting the connection timeout to imaginary numbers
When asked to optimize runtime, this candidate discovered that negative sleep() is the ultimate performance hack - it's so fast, it travels backward in time! Who needs thread.join() when you can busy-wait with undefined behavior? The interviewer's chess analogy is apt: this move is so brilliant, it's like sacrificing your queen, both rooks, and your dignity in a single turn. At least the filename 'shitpost.py' sets appropriate expectations for code review
Asked to "improve runtime," I threaded it and called sleep(-1); the GIL plus a ValueError delivered the only true O(1): instant crash
Optimized the function to O(0): spawn a thread, return immediately - throughput unchanged, GIL unimpressed, but the KPI says “outstanding”
Shaves runtime to O(n/cores + eternal polling) - because proper Thread.join() is for architects, not interview gladiators
Lol Comment deleted
what Comment deleted
He makes it run on a different thread Comment deleted
-1? Comment deleted
Can u explain? Comment deleted
why not j0in? Comment deleted
Threads will only use one CPU on your machine with python. Won’t be faster. Idea is funny though -> Use Multiprocessing Comment deleted
wait really? so Python only ever works on one CPU even when I make new Threads? Comment deleted
there are ways to circumvent that, but it's quite complicated Comment deleted
might that be why Python concurrency sucks so much with its restrictions on net-card access only from the main thread and stuff like that? Comment deleted
idk, I haven't actually done much research. I just know that python really doesn't want to be responsible for race conditions Comment deleted
GIL ist the problem and has it's reasons https://realpython.com/python-gil/ Comment deleted
Yeah, it's same for many such languages, ruby too, because GIL That's why if it's about web apps one usually makes workers and forking🤷♂️ Comment deleted
I just write Go instead, lol Comment deleted
Me too, but simple stuff, like poll or smth - Django / Flask :) Comment deleted
Try FastAPI Comment deleted
its very easy. Just use multiprocessing to start a new process. A python Interpreter can only be executed on one cpu. A new process is executed on a new cpu :) Comment deleted
laughs in go func() peasants Comment deleted