Skip to content
DevMeme
220 of 7590
Interviews Post #267 · source on Telegram

Improving Runtime with Malicious Concurrency

Description

A three-part meme about a technical interview. The first part shows text from the 'Interviewer:' asking, 'Can you improve the runtime of this function?'. The second part, labeled 'Me:', displays a Python code snippet from a file named 'shitpost.py'. The code imports 'Thread' from the 'threading' module, starts a function 'my_function' in a new thread, and then enters a 'while' loop with 'time.sleep(-1)' that blocks indefinitely while the thread is alive. The final part shows the 'Interviewer:' again, this time using the 'Outstanding Move' meme format, where a man in front of a chessboard sarcastically praises the solution. The humor stems from the candidate's wildly incorrect solution. Instead of optimizing the function's algorithm to make it computationally faster, they run it in a separate thread. This makes the main program continue immediately, giving the *illusion* of improved runtime, but it doesn't actually speed up the function itself. The 'time.sleep(-1)' is particularly absurd, as it would cause an error in Python, highlighting a complete misunderstanding of both performance and concurrency

Comments

8
Anonymous ★ Top Pick This isn't improving runtime; it's just outsourcing the performance problem to another thread and hoping the main thread dies of old age before it finishes. It's the 'fire-and-forget-to-check-if-it-crashed' pattern
  1. Anonymous ★ Top Pick

    This isn't improving runtime; it's just outsourcing the performance problem to another thread and hoping the main thread dies of old age before it finishes. It's the 'fire-and-forget-to-check-if-it-crashed' pattern

  2. Anonymous

    Wrap the function in one thread, call time.sleep(-1), and suddenly the p99 latency is yesterday - SRE can’t page you for incidents that technically happened in the past

  3. Anonymous

    This is the same optimization strategy I've seen in production: if the function crashes before it finishes, technically it has zero runtime

  4. Anonymous

    time.sleep(-1) is the only optimization that targets the calling convention of causality - sadly Python raises ValueError instead of inventing tachyons

  5. Anonymous

    Ah yes, the classic 'optimization' strategy: spawn a thread to run your function asynchronously, then immediately block the main thread in an infinite loop polling its status with a negative sleep duration. It's like ordering food delivery to save time, then standing at the restaurant door watching them cook it. Bonus points for the `time.sleep(-1)` - because when the interviewer asks you to improve runtime, clearly they meant 'make it crash faster.' This is the kind of solution that makes you wonder if the candidate's previous role was 'chaos engineer' or if they're just really committed to the bit

  6. Anonymous

    In Python, spawning a Thread under the GIL and busy‑waiting on isAlive() with time.sleep(-1) makes runtime “negative” and correctness imaginary - truly enterprise-grade optimization

  7. Anonymous

    Spawned the function in a thread and went to sleep - classic latency theater; with Python’s GIL, the only thing that scaled was the interviewer’s optimism

  8. Anonymous

    Python threading 'optimization': shave seconds off CPU time by burning them on context switches and GIL contention - Amdahl's law laughs last

Use J and K for navigation