Skip to content
DevMeme
3099 of 7590
Interviews Post #3415 · source on Telegram

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

25
Anonymous ★ Top Pick My function's runtime is now O(ε), where ε is the time it takes the Python interpreter to process a fatal error. Your move, interviewer
  1. Anonymous ★ Top Pick

    My function's runtime is now O(ε), where ε is the time it takes the Python interpreter to process a fatal error. Your move, interviewer

  2. Anonymous

    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

  3. Anonymous

    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

  4. Anonymous

    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

  5. Anonymous

    Asked to "improve runtime," I threaded it and called sleep(-1); the GIL plus a ValueError delivered the only true O(1): instant crash

  6. Anonymous

    Optimized the function to O(0): spawn a thread, return immediately - throughput unchanged, GIL unimpressed, but the KPI says “outstanding”

  7. Anonymous

    Shaves runtime to O(n/cores + eternal polling) - because proper Thread.join() is for architects, not interview gladiators

  8. @ZgGPuo8dZef58K6hxxGVj3Z2 5y

    Lol

  9. @nuntikov 5y

    what

    1. @ZgGPuo8dZef58K6hxxGVj3Z2 5y

      He makes it run on a different thread

  10. @nuntikov 5y

    -1?

  11. @bezuhten 5y

    Can u explain?

  12. @nuntikov 5y

    why not j0in?

  13. @t02x2 5y

    Threads will only use one CPU on your machine with python. Won’t be faster. Idea is funny though -> Use Multiprocessing

    1. @viktorrozenko 5y

      wait really? so Python only ever works on one CPU even when I make new Threads?

      1. @RiedleroD 5y

        there are ways to circumvent that, but it's quite complicated

        1. @viktorrozenko 5y

          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?

          1. @RiedleroD 5y

            idk, I haven't actually done much research. I just know that python really doesn't want to be responsible for race conditions

      2. @t02x2 5y

        GIL ist the problem and has it's reasons https://realpython.com/python-gil/

      3. @slnt_opp 5y

        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🤷‍♂️

        1. @viktorrozenko 5y

          I just write Go instead, lol

          1. @slnt_opp 5y

            Me too, but simple stuff, like poll or smth - Django / Flask :)

            1. @viktorrozenko 5y

              Try FastAPI

  14. @t02x2 5y

    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 :)

  15. @Dexconv 5y

    laughs in go func() peasants

Use J and K for navigation