python is too slow...

Поділитися
Вставка
  • Опубліковано 10 лют 2025
  • ... for a text editor? I talk about the architecture of babi and how I made it "fast enough" and ultimately that "sometimes it doesn't matter if it's slow"
    playlist: • anthony explains
    ==========
    twitch: / anthonywritescode
    dicsord: / discord
    twitter: / codewithanthony
    github: github.com/aso...
    stream github: github.com/ant...
    I won't ask for subscriptions / likes / comments in videos but it really helps the channel. If you have any suggestions or things you'd like to see please comment below!

КОМЕНТАРІ • 110

  • @ericng8807
    @ericng8807 5 днів тому +154

    Lemme open up my text editor written in javascript that imports a browser to show you how it's done

    • @anthonywritescode
      @anthonywritescode  5 днів тому +28

      true. I should have timed `code babi/screen.py` as a fair comparison 😂

  • @senseikoudai6186
    @senseikoudai6186 День тому +2

    I would love a video tutorial on how to create these plots/flowcharts to investigate which part of your code takes what amount of time.

  • @gremblexyz
    @gremblexyz 4 дні тому +10

    "Sometimes it is okay to be slow" is a wonderful affirmation

  • @spencer3752
    @spencer3752 4 дні тому +15

    My father researched psychology with respect to how users (specifically, a POS terminal operator) responds to user interfaces. Users actually have an easier time cognitively switching between screens (and thereby an easier time switching tasks) in the software when the UI goes blank for at least a perceivable (but still very small) amount of time. If the program switches screens too quickly, the user's brain is 'left behind' in the previous screen context and so they have a harder time switching tasks quickly. So, he programmed his POS software to intentionally have a short delay when switching screens. This actually improves user productivity. Or at least that's what some studies would suggest.

    • @prashanthb6521
      @prashanthb6521 3 дні тому

      nice

    • @AnthonyBurback
      @AnthonyBurback 3 дні тому

      what made the terminal operator a piece of shit?

    • @callowaysutton
      @callowaysutton День тому

      I was a little obsessed with HCI for a bit and this is actually just a misconceived rumor. The broader research suggests that intentionally inducing wait times or hiding information which would otherwise be instantaneous generally harms user experience rather than helping it. Nielsen (1993) found that users expect near-instant feedback-around 0.1 seconds feels instantaneous, while delays around 1 second disrupt flow and cause frustration. Studies like Rogers and Monsell (1995) and Monsell (2003) do show that visual cues for state changes is important, but they also show that it's only for longer running tasks that would already be in the second to multi-second range; anything less than that and it's been found to be jarring and/or unnecessary

  • @po6qu7
    @po6qu7 5 днів тому +7

    Out of topic, but this moment when you realise your Python boy crush is actually the originator of pre-commit, mind blown...
    Great content, as always! :-)

  • @DimaCoffee
    @DimaCoffee 5 днів тому +10

    Most people when editing videos would cut part when Anthony is trying to figure out what’s wrong with identify module, but it is so nice to see that sometimes things mess up even if you are really experienced
    Thanks for your videos, learned a lot from them, to some extend thank you that made me Python-ish enough to get my first job 4 years ago

    • @anthonywritescode
      @anthonywritescode  5 днів тому +3

      heh yeah I tend to not edit unless I'm doing something that's going to get me in trouble. plus it was late at night and after a beer and I decided wevs

  • @makur0
    @makur0 5 днів тому +14

    The -S mixup is sending me

    • @jtw-r
      @jtw-r 5 днів тому +5

      but is it -sending you or is it -Sending you??

  • @FunkyELF
    @FunkyELF 5 днів тому +14

    Python is my go to language. I was learning some JS/TS in December and decided to do some Advent of Code.
    One problem in particular I decided to code in Python and noticed it was twice as slow (32s compared to 17s).
    I jumped on IRC and asked in #python what V8 could be doing that makes it twice as fast. They mentioned it could be JIT related and asked that I try it in pypy.
    To my amazement pypy was able to run it in just 2.5 seconds w/ the same code.
    CPython: 32
    Deno (V8): 17
    PyPy: 2.5
    Crazy stuff

    • @anthonywritescode
      @anthonywritescode  5 днів тому +5

      pypy's jit is pretty great -- especially for advent of code where it's usually running an extremely homogeneous workload

  • @ianchui
    @ianchui 5 днів тому +2

    Great video Anthony! I love watching to an Anthony writes code video during breakfast (:
    I love the topic of perceived performance

  • @Spitfire5592
    @Spitfire5592 5 днів тому +28

    To mention, if your client is on a 240hz monitor you have 4ms to complete the action without introducing delay.

    • @anthonywritescode
      @anthonywritescode  5 днів тому +19

      that's only true if you can perceive 240hz

    • @MaxCoplan
      @MaxCoplan 4 дні тому +2

      @@anthonywritescode and everyone knows you can't perceive more than 30hz

    • @CrossbowBeta
      @CrossbowBeta 4 дні тому +5

      @@anthonywritescode so like everyone?

    • @d3stinYwOw
      @d3stinYwOw 4 дні тому +4

      @@anthonywritescode Yes, you can perceive it, but we start to dig more into 'feeling' than 'seeing'

    • @Summersault666
      @Summersault666 4 дні тому +1

      Your SSD is the bottleneck

  • @octaviaefraim1336
    @octaviaefraim1336 2 дні тому +1

    Hi Anthony. Sorry, this is a bit off topic, but could you please share your keyboard / trackball setup? I've been looking for a good split keyboard for some time. I've tried a few but still haven't found one that I'm happy with. Thanks!

    • @TheMadMagician87
      @TheMadMagician87 15 годин тому

      I second this, curious to hear how your setup has worked for you Anthony.

  • @randomneo4538
    @randomneo4538 5 днів тому +4

    there is treesitter syntax highlighter quite fast. A lot of editors use it now days. Have you considerate moving to it?

  • @timmywelch7231
    @timmywelch7231 5 днів тому +2

    I ran into an issue recently where requests was proving to be slow (being on sometimes flakey mobile/public wifi didn't help) but downloads went twice as fast using curl instead and it was simpler to call the curl binary than to use a different library for the large downloads

  • @pablogonzalez7959
    @pablogonzalez7959 5 днів тому +1

    Good video, but I will love something more in detail about maybe what is somethings that you should avoid when writing python (because slowness), how to measure execution times, and what things are fast in python

  • @gentlemanbirdlake
    @gentlemanbirdlake 4 дні тому

    1:35 The real slowness was maintaining the package dependencies we made along the way

  • @tan.nicolas
    @tan.nicolas 4 дні тому

    anthony you are so cool, thanks for all your amazing work!

  • @jamesfitzpatrick9607
    @jamesfitzpatrick9607 5 днів тому +5

    I think contexts matters a lot. Yes, python is slow. Yes, there are fast options out there. Yes, I am currently using python to load test and collect data from golang application running in k8s. I think the use case matters a lot.

    • @vitalyl1327
      @vitalyl1327 4 дні тому

      @@jamesfitzpatrick9607 it is extremely hard to.justify a single use case for Python. Its "simplicity" is a myth. It is a low level language, so it does not really imporve the development time and costs. It is just popular, because worse is better.

  • @cetilly
    @cetilly 4 дні тому

    I am going to check out your editor. I had no idea.

  • @sillybuttons925
    @sillybuttons925 5 днів тому +2

    Now... let's discuss the networking stack for a moment :p

  • @Heater-v1.0.0
    @Heater-v1.0.0 День тому

    Modules screwed up in the first minute. That happens to me every time I try to use Python for anything. Been happening for years with no sign of improvement. So much so that people have given me Python code in Docker containers recently. One of the many reasons for my never wanting to use Python.

  • @er63438
    @er63438 4 дні тому

    I definitely need to hear more about that type hint! WTF

  • @mrswats
    @mrswats 5 днів тому +22

    You should certainly rewrite it in C

    • @anthonywritescode
      @anthonywritescode  5 днів тому +34

      C deez

    • @mrswats
      @mrswats 5 днів тому +5

      @anthonywritescode that's my boi

    • @whythosenames
      @whythosenames 5 днів тому +4

      Why not in rust?

    • @NostraDavid2
      @NostraDavid2 5 днів тому +5

      @whythosenames Because Rust isn't cool anymore - it's Zig, or even Odin nowadays.

    • @DeeaA-o5z
      @DeeaA-o5z 5 днів тому +4

      Rust was never cool

  • @thingsiplay
    @thingsiplay 5 днів тому +2

    I used Qtile for years, tiling window manager written and configured in Python. It always felt snappy... well until there was a huge mouse problem with high polling rates. I think its fixed now, but that counts as a bug. Also there are lot of tools written in Python, like yt-dlp where the slow parts of Python just doesn't matter.
    Then there are optimized libraries that use C in the backend. Its a bit cheating, but basically every language cheats by using C. And there is Pypy too.

  • @xan1716
    @xan1716 5 днів тому +1

    Hey Anthony, do you recommend using the future annotations import in every file? Was curious whether the performance issue in its absence was still a significant thing in more recent versions of python

    • @anthonywritescode
      @anthonywritescode  5 днів тому +1

      I use it in every file. there's some certain libraries that I avoid that it doesn't play nicely with but I avoid them

  • @AYUSHPORWAL-s9m
    @AYUSHPORWAL-s9m 4 дні тому

    nice start of the video, "WTF is wrong" lmao

  • @hansdietrich1496
    @hansdietrich1496 4 дні тому

    For 95% of my "python is slow"-issues, numba is the perfect solution.

    • @anthonywritescode
      @anthonywritescode  4 дні тому

      that's not really the point of the video. also numba is usually hilariously overkill and is a nightmare from a packaging compatibility perspective

    • @hansdietrich1496
      @hansdietrich1496 4 дні тому

      @ My usecase is usually number crunching and packaging was no issue so far fortunately. But yeah, I totally understand it might not be a good a solution for other use cases.

  • @d3stinYwOw
    @d3stinYwOw 4 дні тому

    It would be interesting to see benchmarks of different python 'flavors' on example of babi - CPython, PyPy and Codon :)

  • @kamurashev
    @kamurashev 5 днів тому

    I’m not a huge fan of python but it’s 💯 % true.
    One note though, until it starts to matter. Unfortunately in a lot of cases the only thing that is left to do is a rewrite.

  • @brodie659
    @brodie659 5 днів тому

    I make the face at 2:06 quite a few times a day. Love to see it's not just me!

  • @dandreani
    @dandreani 4 дні тому

    i don't think `neovim` is any faster than `babi` startup once you start adding all the dependencies and plugins.

  • @Bravo-oo9vd
    @Bravo-oo9vd 5 днів тому +3

    2:40 "startup time of an application is pretty important, but for a text editor? i don't know if it's that important"
    ah, so it's safe to guess you don't use VS Code very often?

    • @hansdietrich1496
      @hansdietrich1496 4 дні тому

      Yeah, but how often do you restart your IDE? Once a day? Once a week? Sure, faster is never wrong, but I'd agree, not such a big deal compared to other criteria.

    • @d3stinYwOw
      @d3stinYwOw 4 дні тому

      @@hansdietrich1496 Depends on language, some people need to restart their editor often, because LSP is written so bad (ekhm typescript one ekhm) that without restart you will have more trouble

    • @anthonywritescode
      @anthonywritescode  4 дні тому +3

      actually that's part of the reason I don't use vs code

  • @dmytr0x
    @dmytr0x 5 днів тому +4

    ‘:comment +’ ❤

  • @0xDomain
    @0xDomain 5 днів тому

    Did you have prior knowledge of how tect editors worked or you just figured out how things worked along the way as you were building it out?

  • @victordvickie
    @victordvickie 5 днів тому

    have you explored treesitter based highlighting?

    • @anthonywritescode
      @anthonywritescode  4 дні тому +1

      unfortunately I started the project mere months before treesitter existed slash was popular so I haven't

  • @muddasirkhan805
    @muddasirkhan805 5 днів тому

    Hi Anthony - would you have any tips/best practices when using a vendor api to do crud operations? How would you build out a project for something like this and say maybe make a cli tool?

    • @anthonywritescode
      @anthonywritescode  5 днів тому +2

      record requests and responses and write a bunch of tests around those. periodically refresh the recorded responses to make sure they're reasonable. have monitoring around success rate of interactions. and beyond that Ts and Ps :)

    • @muddasirkhan805
      @muddasirkhan805 4 дні тому

      @ :) thanks for responding!

  • @davidecologni2851
    @davidecologni2851 5 днів тому

    Hi, if you optimized some cpu intensive part do you have some general tips like the one about typing or you generally figure out optimization based on which part is slow in the profiler?

    • @anthonywritescode
      @anthonywritescode  5 днів тому

      general tips are sort of useless (even the type annotation one: it was only load bearing because it was in a tight loop but otherwise wouldn't have been impactful at all). profile it to find what's slow and optimize from there

  • @tylermfdurden
    @tylermfdurden 5 днів тому +7

    People that say python is slow are the same people who buy 240 Hz monitors and an expensive laser mouse so they can lose at Starcraft because they're

    • @bluemeriadoc
      @bluemeriadoc 5 днів тому +3

      99% of python use cases, not 99% of software use cases. python use cases are definitionally the subset that tolerate extreme slowness

    • @vitalyl1327
      @vitalyl1327 5 днів тому +1

      In 99% of my use cases Python itself won't even fit onto a device I'm writing code for.

    • @tylermfdurden
      @tylermfdurden 5 днів тому

      @@vitalyl1327 Congrats, you are the 1%

    • @vitalyl1327
      @vitalyl1327 4 дні тому

      @tylermfdurden in the era of the cloud and costs per CPU time, 100% must care about their code perfotmance. Those who still use Python are delusional.

    • @Al-.-ex
      @Al-.-ex 3 дні тому

      @@vitalyl1327 you definitely spend your time wisely.

  • @ozanhb
    @ozanhb 5 днів тому

    Are you sure that those import list runs at every key press? Are you evaling a py file? Otherwise, a key press should run a callable which was already imported once by the interpreter. Or I forgot python because I dropped it at v2.7~3.1

    • @legion_prex3650
      @legion_prex3650 5 днів тому

      Its not imported on every key press, the page is RENDERED (probably with curses? @anthonywritescode) on every key press. In games development, the canvas is rendered 60 times per second. So, that is pretty normal.

    • @anthonywritescode
      @anthonywritescode  5 днів тому +2

      ah you're misinterpreting. it has to *highlight and render* all of that on every execution.

    • @ozanhb
      @ozanhb 5 днів тому

      Got it thank you for the heads up 👌

  • @Summersault666
    @Summersault666 4 дні тому

    Just run in mojo environment

  • @henrymorgan9445
    @henrymorgan9445 5 днів тому

    If you shift nano over by one you get bBI

  • @geerliglecluse5297
    @geerliglecluse5297 5 днів тому +3

    Anthony, are you aware of the fun-fact that "babi" happens to mean "pig" in Indonesian? Or was that somehow intentional?!

    • @b_0rk
      @b_0rk 5 днів тому +1

      it's just a typo of "nano"

    • @anthonywritescode
      @anthonywritescode  5 днів тому +2

      I actually explain the name at the beginning. unfortunately I'm not fluent in every language so the overlap in others is just going to be inconvenient

  • @thunder____
    @thunder____ 5 днів тому

    I guess that's all well and good if your goal is just to write working software to address actual real-world use cases, but isn't the REAL purpose of programming to feel superior? That's why I only write assembly, Rust, and Brainfuck

  • @yakimka5620
    @yakimka5620 5 днів тому +1

    Hello and welcome to another video... ? 😩

  • @legion_prex3650
    @legion_prex3650 5 днів тому

    love it

  • @bugtank
    @bugtank 5 днів тому +1

    It’s funny cause yeah it’s slow and that’s ok!

  • @kesslerdupont6023
    @kesslerdupont6023 5 днів тому

    What are the specs on your computer?

  • @essamgouda1609
    @essamgouda1609 5 днів тому +1

    am too fast tho

  • @Munchopen
    @Munchopen 5 днів тому

    Lol... most websites perform way worse than Babi. :D

  • @koletackney
    @koletackney 5 днів тому +2

    1:30 is pythons true biggest fault.

    • @yakimka5620
      @yakimka5620 5 днів тому

      what? running your code with disabled importing of site module?

    • @guillemgarcia3630
      @guillemgarcia3630 5 днів тому +1

      @@yakimka5620 really man? you really have no problem with what just happened there?

    • @anthonywritescode
      @anthonywritescode  5 днів тому +4

      the -S flag worked exactly as intended "don't load site". it was entirely operator error here on an exceedingly rare flag while recording late at night after a beer and a very long day

    • @koletackney
      @koletackney 5 днів тому

      ​@@anthonywritescodefor sure, I am just saying python has so many foot guns around dependencies around imports. Great video btw, definitely didn't know type annotations would impact performance.

    • @anthonywritescode
      @anthonywritescode  5 днів тому +1

      I don't really agree (and the thing in the video definitely isn't one people would ever run into unless they're me). the only one I can really think of is if you run a script vs a module but ez don't run as a script. and I guess cycles but also just don't have cycles

  • @bluemeriadoc
    @bluemeriadoc 5 днів тому

    doesn't matter unless you want to not spend long hours optimizing and still be too slow to go full IDE

    • @anthonywritescode
      @anthonywritescode  5 днів тому +1

      I think you missed the entire point. the structure was set up specifically to be simple and not worry about micro optimizing because it's fast enough

  • @sorvex9
    @sorvex9 5 днів тому +2

    Uhhhh…. Vim

  • @pietraderdetective8953
    @pietraderdetective8953 5 днів тому +1

    To make Python fast is very easy: compile your Python using Codon.
    10-200x speedup is that easy.

    • @b_0rk
      @b_0rk 5 днів тому

      Codon deez nuts

  • @rednafi
    @rednafi 5 днів тому +2

    I/O is slower.

    • @anthonywritescode
      @anthonywritescode  5 днів тому +3

      I/O is going to be about the same in every language

    • @rednafi
      @rednafi 4 дні тому +1

      @@anthonywritescode Sorry, I meant that I/O is slower than Python and many applications spend the bulk of the time in I/O. Python works!