This Algorithm is 1,606,240% FASTER

Ғылым және технология

7 Steps it took to make an algorithm 1,606,242% faster!!!!
Become a backend engineer. Its my favorite site
boot.dev/?promo=PRIMEAGENYT
This is also the best way to support me is to support yourself becoming a better backend engineer.
David Perez
github.com/david-a-perez
B3NNY
/ _b_3_n_n_y_
Bit video
• Bit and Byte Explained...
Code used in video
github.com/ThePrimeagen/aoc/b...
Twitch
Everything is built live on twitch
Twitch : bit.ly/3xhFO3E
Discord: discord.gg/ThePrimeagen
Spotify DevHour: open.spotify.com/show/4MLaDrQ...
Editor
All my videos are edited by Flip. Give him a follow! / flipmediaprod He is also open to do more editing, so slide deeeeeeeeep into his dms.
Join this channel to get access to perks:
/ @theprimeagen
Links
Linode: linode.com/prime
/ discord
Twitch: / theprimeagen
Insta: / theprimeagen
Twitter: / theprimeagen
VimRC & i3: github.com/ThePrimeagen/.dotf...
Keyboard 15% off bit.ly/Prime360 USE CODE PRIME360
#coding #neovim #typescript #programming #vim #softwareengineering #codinglife #webdesign #webdevelopment #webdev #javascript #rustlang #rust #twitch #twitchstreamer #programmerhumor #codinghumor #software #softwareengineer #softwaredeveloper #softwaredevelopment

Пікірлер: 875

  • @10e999
    @10e999 Жыл бұрын

    Exactly. It's not about Rust vs C vs Cpp vs Zig. It's about how much you understand system programming.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    yayaya

  • @rutabega306

    @rutabega306

    Жыл бұрын

    Rust vs Cpp vs C vs Zig is still an important question, but the differences are stuff like memory safety and maintainability

  • @RustedCroaker

    @RustedCroaker

    Жыл бұрын

    it's not understand of system programming. it's general understanding how a hardware works irl

  • @askeladden450

    @askeladden450

    Жыл бұрын

    that's true for algorithms but not for data. how your data is laid out in memory is just as important as the algorithm, and some languages limit the control you have over memory allocation, which makes them unsuitable for any program that deals with large amount of data, like games, audio systems etc.

  • @seanknowles9985

    @seanknowles9985

    Жыл бұрын

    Zig has clean simple syntax like Go with 90% of Rusts safety and are continually decreasing the margin between Rust and Zig's safety gap. It may even get to parity party soon on safety but with a much cleaner API and the entire C lib interop. I have a strong feeling Zig will take the cake within the next few years.

  • @slurpe_ee
    @slurpe_ee Жыл бұрын

    as a beginner developer, seeing you go from an array to bit manipulation was like watching black magic. incredible to see what we can do with these technologies and break them down to their atomic pieces.

  • @MrHaggyy

    @MrHaggyy

    Жыл бұрын

    Oh you should definetly look into bit and byte representation of several native datatypes. Even if you later code in something really high level aligning data correctly makes everything soo much faster. And some compilers will choose bitmanipulation over actual multiplication or division if you can keep something in a power of two for example.

  • @tdsdave

    @tdsdave

    Жыл бұрын

    @@MrHaggyy Could you not replace the mod 32(decimal) with And 011111(binary) , I can't make out from the disassembly( been a long time ) how the modulus operator is compiled. But being mod 32 the remainder of that will be the result of And 11111. Mod if compiled as a instruction using division/remainder takes longer clock cycles to execute than an And. At least that is how it seems to me.

  • @TheSkepticSkwerl

    @TheSkepticSkwerl

    Жыл бұрын

    But manipulation is a lot simpler than it seems. The hard part is determining where to use it. Definitely test for performance as you use it.

  • @Simmons101

    @Simmons101

    11 ай бұрын

    It can be hard and tricky to implement, but if you can learn how to quickly go up and down in levels of abstraction, it can make all the difference.

  • @PhilfreezeCH

    @PhilfreezeCH

    9 ай бұрын

    For anyone who is interested into these kinds of algorithms. Go look into genome matching algorithms and also in-memory processing. Both categories heavily depend on these kinds of bit manipulation algorithms to optimize known problems like searching for a exact or fuzzy match.

  • @ThePrimeagen
    @ThePrimeagen Жыл бұрын

    Tell me you were surprised by using a vector to speed up instead of using a hashset but telling me i am beautiful (and liking the video) Slight correction. When I say left shift is multiplied by 10, I meant 10 in binary. Therefore it is two in decimal

  • @brightonsikarskie8372

    @brightonsikarskie8372

    Жыл бұрын

    it did surprise me. I was always confused how a hashset was O(1) just like a vector. I didn't realize it was O(1*c) which makes wayyyy more sense. Also the bits I didn't know so thank you :)

  • @AquaEBM

    @AquaEBM

    Жыл бұрын

    SipHash 1-3 (rust collections' default hashing algorithm) is fairly slow for integer keys, so this is kinda to be expected, I am quite surprised a vec is faster though, genius move.

  • @NotBlackyy

    @NotBlackyy

    Жыл бұрын

    It does make sense. My mind immediately jumped to the u32 "set", as I have seen it used before :D The threading was cool, but c'mon, only 64 threads? Should've used a 128 core ;)

  • @laupetre

    @laupetre

    Жыл бұрын

    I have started reading the Learning Rust with Entirely Too Many Linked Lists, and it has a link to a clip of mr Bjarne S. Talking about vectors vs lists, and why one should use vectors most of the time

  • @NathanHedglin

    @NathanHedglin

    Жыл бұрын

    You're beautiful

  • @DrOptix
    @DrOptix Жыл бұрын

    This is really awesome because you don't just show the final kick ass solution, but also present a mental model on how to get from the naive solution to the fast one.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    Yayaya

  • @watynecc3309

    @watynecc3309

    Жыл бұрын

    @@ThePrimeagen That's why you're the best waifu

  • @kuklama0706

    @kuklama0706

    7 ай бұрын

    This is actually to increase watch depth of the video. You know the next one will be better so you keep watching.

  • @fishfpv9916
    @fishfpv9916 Жыл бұрын

    Really like videos going over practical algerithm optimization. I feel in school there is a lot of focus on theory and very little on how to make things run fast in the real world. Love to see more of these types of videos!

  • @josuealexandericujac7083

    @josuealexandericujac7083

    Жыл бұрын

    fast? you mean blazingly fast?

  • @5FT6MAN

    @5FT6MAN

    Жыл бұрын

    so true...cs teachers are setting us up to fail oh well thank god for chtGPT

  • @climatechangedoesntbargain9140

    @climatechangedoesntbargain9140

    Жыл бұрын

    Theory is important

  • @brainsniffer

    @brainsniffer

    Жыл бұрын

    I feel like we talk a lot about solving problems, and if it’s an acceptable result, that’s good enough. Most of the time, I am completely unaware that things even can be optimised this much. Blows mind.

  • @HongHaiNguyenx

    @HongHaiNguyenx

    Жыл бұрын

    How can u do optimization without knowing some basic theories?

  • @yungclowns
    @yungclowns Жыл бұрын

    In the (relatively common) case where there's a 14-character window with more than one duplicate, going backwards within the window allows you to find the duplicate furthest along in the input. This means you can skip ahead further in those cases. It is a good example of a 'greedy' optimization looking for the best case (a late duplicate) first.

  • @nimmidev9122

    @nimmidev9122

    Жыл бұрын

    But what is the difference between finding the duplicate from back to front first or from front to back? You can skip ahead either way, right? Or am i missing something (which is likely because its 4AM)?

  • @TheJocadasa

    @TheJocadasa

    Жыл бұрын

    ​@@nimmidev9122 Consider the example "oabcaefghijlml...". Looking at the first window, 'oAbcAefghijLmL'. If we check from the front, once we encounter the second 'A', we will start the next window after the first occurrence of that character, skipping 1 window. But, if we check from the back, once we find the second (right-to-left) 'L', we will start the next window before the second occurrence of that character, skipping 10 windows. Since we are predictably accessing only 14 bytes at a time, prefetching and, by extension, reading backwards should not be an issue. On average, we will end up skipping more windows going backwards.

  • @koktszfung

    @koktszfung

    Жыл бұрын

    ​@@nimmidev9122 try the easiest case of "aaaaa aaaaa aaaa...", if you go from the front, you can't skip ahead, if you go from the back, you can skip ahead, so they are clearly different. But I don't know if there are any case where going from the front is beneficial

  • @nimmidev9122

    @nimmidev9122

    Жыл бұрын

    @@TheJocadasa Yee, makes much more sense now. Idk what i was thinking. Should probably stop watching such content in the middle of the night 😅 Thanks for the explanation.

  • @David-id6jw

    @David-id6jw

    Жыл бұрын

    But what if you have abcdefghijklman? The first duplicate is the second 'a' in the 14th position, but the first unique sequence is the b-n run. If you skip to the second 'a', you miss that entire sequence. Or if you want more than one duplicate, change the 'c' to a 'b' and add an 'o' at the end (abbdefghijklmano). Now the correct sequence is b-o. Either way, it feels like it would miss correct solutions.

  • @PanduPoluan
    @PanduPoluan Жыл бұрын

    And a note of caution: Although yes the performance increases significantly, the more optimised it becomes, the more specialised and hard to maintain it will also be. For the purposes of the Advent of Code challenge, it's perfectly suitable. However for daily development, the tradeoffs need to be considered really carefully. Finally, before going down the rabbit hole of extreme optimisation, don't forget to *profile your code first* ! You don't want to spend an inordinate amount of time hyper-optimizing a portion of your code that only affects 1% of total execution time. Find pieces of code that affects 10% or more of execution time and focus your efforts there first.

  • @joaobibiano

    @joaobibiano

    Жыл бұрын

    You hit the nail on the head

  • @itellyouforfree7238

    @itellyouforfree7238

    11 ай бұрын

    this mindset is why today we need 500MB to install a shitty app on a phone. back when resources were scarse, it was people job to come up with clever optimizations and techniques. nowadays people are just lazy and hide behind the "premature optimization" bullshit

  • @itellyouforfree7238

    @itellyouforfree7238

    11 ай бұрын

    for a task of the sort as presented in the video, there is NO REASON AT ALL to stick with the "simple" solution. the clever algorithm reminds of en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm and is something any decent programmer is supposed to understand easily (possibly with introductory comments to explain some details). the best practice would be to code the optimized algorithm and unittest it against the simple reference solution for correctness.

  • @Quazgaa

    @Quazgaa

    10 ай бұрын

    This sort of mewling adds nothing. "Be sure to check whether the floor is dirty before mopping the floor or else it will be a waste of time" is not the brilliant insight you want it to be. What's really going on is that people like you are often coming from a corporate managerial sort of mindset where you want all your cogs to churn out the most uniformly basic code humanly possible with no intelligent or individualized thought given to things like engineering or efficiency, but saying that out loud in so many words doesn't sound very sexy so instead you go around offering your contempt for people who enjoy the prospect of writing better code as if it is some sort of counter-intuitively enlightened insight you have descended from the heavens to grace us with, but it is no such thing.

  • @NuclearAmouri

    @NuclearAmouri

    6 ай бұрын

    This reminds me of the FISR algorithm in Quake 3 that enabled it to run blazingly fast. That was a beautiful abomination peice of code. I wonder whether there are tools that calculate which of your functions take the most overall time.

  • @brendanwenzel
    @brendanwenzel Жыл бұрын

    More of this is needed! I never knew I needed to know this stuff. Best part of KZread is getting mentored by a senior dev without having to be in the same office!

  • @yt-sh

    @yt-sh

    Жыл бұрын

    can you recommend some other senior devs on youtube who teach good concepts...

  • @softwareamedida

    @softwareamedida

    11 ай бұрын

    Awesome way of thinking!!

  • @ExpertOfNil
    @ExpertOfNil Жыл бұрын

    Awesome video, thank you! I love it when you dive into the lower-level aspects of programming. Also a nice reminder that approximations can obfuscate significant differences.

  • @tagon35
    @tagon35 Жыл бұрын

    Love this content. Really cool and even though I haven't looked at some of the concepts for a while, i can tell you've got fundamental knowledge to bank on. Can't wait to see more!

  • @BreakbeatNightmare
    @BreakbeatNightmare Жыл бұрын

    More videos like this please! Love the deep dive into blazingly fast computer science topics

  • @ryandevenney8878
    @ryandevenney8878 Жыл бұрын

    Long time fan and this is my favorite video I’ve seen from you, more of this please!!

  • @anonymmc2764
    @anonymmc2764 Жыл бұрын

    Tbh this might be my favorite video of you so far. Very well explained, hats off to you! Also congratz to David for the solution, very clever stuff!

  • @Green_44_
    @Green_44_ Жыл бұрын

    This is the kind of breakdown I’ve been looking for!! Thank you and your family for this content 😅

  • @arjanbal3972
    @arjanbal3972 Жыл бұрын

    It's not mentioned, so one way to split the problem for multiple threads, is to divide the string into 64 pieces and ask each thread to solve one piece. You would also need to extend the boundaries of each piece by 14 (maybe 13?) characters on one side so that you can catch 14 size windows that are in multiple pieces. Report the min index from all threads as the final answer.

  • @daedalus_00

    @daedalus_00

    Жыл бұрын

    That would parallelize the list, but has 1 minor issue. We are looking for the first instance of a unique string, and one of the threads could find a unique string later in the sequence before the threads looking through the beginning of the sequence found the first unique string. Maybe, set up a queue for the threads. There are different ways to do so, and in this instance, you could set up two variables. queue_end = total_string_length - window length queue_value = 0 A thread would take a window with its starting position at queue_value and increment queue_value by one, so that the next thread would take the next window, and so on, until one of the threads found a unique sequence or queue_value reaches queue_end

  • @LtdJorge

    @LtdJorge

    Жыл бұрын

    ​@@daedalus_00just do one window per thread. Mark the order of the threads and return the lowest occurrence that no windows to complete before it.

  • @loam

    @loam

    Жыл бұрын

    @@LtdJorge And that all will be slower, because threads in programming language are abstractions, that involve allocation lots of memory and creating bunch of stuff, but in the fastest solution in the video there's direct use of simd instructions of the processor, which is on the whole another level

  • @arjanbal3972

    @arjanbal3972

    Жыл бұрын

    @@daedalus_00 Every thread will return the index where it found the first unique string. This index is the index in the original string and not the smaller piece. So we can take the minimum of the indexes returned by all the threads at the end as the final answer.

  • @arjanbal3972

    @arjanbal3972

    Жыл бұрын

    @@loam Multi threading works along with SIMD. The function that solves each part of the whole string is exactly the same as the one that solves the entire string with SIMD alone. If the input is large enough, the multi threading optimization can be taken a step further by using GPUs and distributed systems. Both optimizations have their pros and cons.

  • @jonathangodar4239
    @jonathangodar4239 Жыл бұрын

    Loved the format of this video, it was explained so nicely and very easy to follow! Ty

  • @darkfire2703
    @darkfire2703 Жыл бұрын

    Nice explanation! I pretty much went for full speed with no regards for readability / maintainability with this AoC (using rust ofc lol). I managed to get my day 6 solution down to about 4 microseconds on one of the discord callenge bots and I had a rather similar approach to you. The performance on the bot was a bit flakey, but some guy had it down to 2us on the bot which was what I got locally on my ryzen 7 2700x

  • @zzzurreal5370
    @zzzurreal5370 Жыл бұрын

    Thank you . Great content. I’m not very proficient with material related to any STEM type of work but I was very interested in this video

  • @alexandersemionov5790
    @alexandersemionov5790 Жыл бұрын

    I just had my imposter syndrome gone, and then I watched this video. Damn it! Great video, a lot of small details and bits of information. Being a nerd is a lot of fun. Thanks ;)

  • @ChillAutos
    @ChillAutos Жыл бұрын

    This is the best content on KZread. I'm about to do your algo course on front-end masters, cant wait.

  • @LeandroCoutinho
    @LeandroCoutinho Жыл бұрын

    This was extremely useful! Please more of this when you can. Lots of Advent of Code days to play with xD

  • @daltonyon
    @daltonyon Жыл бұрын

    Amazing, I really love this type of content and inspire me to always thinking about performance

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    my man! i forgot to say thanks for the comment. I like making these videos because its fun!

  • @daltonyon

    @daltonyon

    Жыл бұрын

    @@ThePrimeagen Anytime!! I'm waiting for more videos like that!!!

  • @Nintron
    @Nintron Жыл бұрын

    This deep dive into optimization was fantastic! Keep up the great content Prime.

  • @PauloMiello
    @PauloMiello Жыл бұрын

    Honestly this was such a great video congrats and thanks!

  • @iamtheV0RTEX
    @iamtheV0RTEX Жыл бұрын

    @9:40 You don't actually have to collect up all the elements in the iterator for this! In Rust, if an iterator implements DoubleEndedIterator then it can iterate in reverse. std::slice::iter implements this trait, so calling any of the "r" iterator methods will just start counting from the end instead of from the start.

  • @masondeross

    @masondeross

    10 ай бұрын

    The assembly suggests that optimization is being applied by the compiler, since it is already iterating in reverse (over completely unrolled loops). I might be misunderstanding you: are you saying there are more things that don't need iterated (from your first sentence), and the second sentence about reverse iterator was a separate note? I don't use Rust, so "collect up all the elements in the iterator" might have a Rust technical/idiomatic meaning that I am missing.

  • @scottiedoesno
    @scottiedoesno Жыл бұрын

    I watched this all unfold on twitch but love having the video here to review. As someone that didn't get a formal education in CS, this low level stuff is so helpful to be able to return to.

  • @simonfarre4907
    @simonfarre4907 Жыл бұрын

    The stack allocated array and the vector array both have cache locality benefits due to them _both_ being contiguous. The difference is the vector is making a syscall (potentially) to get memory off of the heap. You could reuse the vector after an iteration and you could speed up that variant some. The stack allocated array, gets further cache locality, since you don't even need the first fetch of a cache line - its already in the cache. But both have the benefits of spatial and temporal locality.

  • @frroossst4267
    @frroossst4267 Жыл бұрын

    I'd love more of these code optimization videos, like okay maybe we're not using these techniques and optimizations everyday but so much fun to nerd out about them

  • @wades39
    @wades39 Жыл бұрын

    I'd really love to see more videos like this about how crazy optimization can be. It was really intriguing to see how much overhead there is in what seems like the best approach, and how quickly a solution can run if you remove all of that.

  • @boggledeggnoggler5472
    @boggledeggnoggler5472 Жыл бұрын

    Really cool video, Prime. Learned a lot. Ty!

  • @hk_labs
    @hk_labs Жыл бұрын

    I love this type of content.

  • @guysherman
    @guysherman Жыл бұрын

    Also worth noting that reverse iterators in rust don’t first go forwards, they rely on double-ended iterators, which for things like slices and vectors can start from the end

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    That's only sometimes true. You just have to make sure you have a data structure with a known size.

  • @uwumarie
    @uwumarie Жыл бұрын

    i really enjoyed this video. I would love to see more of these

  • @GameCyborgCh
    @GameCyborgCh2 ай бұрын

    good thing it only did it for 11.9 milli seconds because you'd have a pretty hard time keeping your CPU fed at 617GB/s

  • @white-bunny
    @white-bunny Жыл бұрын

    6:33 That is NOT the Logical AND Operator (which is &&) but actually the Bitwise AND Operator (&). Great video! I learnt a few things here!

  • @IstyManame
    @IstyManame Жыл бұрын

    I have 0 understanding of wtf are you doing but i'm enjoying this so much for some reason, great vid!

  • @rterminatu
    @rterminatu Жыл бұрын

    This video: A+ I really enjoyed seeing some interesting optimisation techniques and in Rust which I am currently learning. Looking forward to some more [amazingly fast] optimisation algorithms and techniques 😁 and in Rust

  • @BobBeatski71
    @BobBeatski7111 ай бұрын

    I'm going to need to re-watch this a few times to get my head around those improvements. 😀

  • @hassan7569
    @hassan75698 ай бұрын

    3:51 you get cache locality with vectors too, it's more about accessing the heap which takes longer than accessing on the stack since everything is known compile time as opposed to having to look up the page (might not or might not be in the TLB), deferencing, etc.

  • @rocamonde
    @rocamonde7 ай бұрын

    I think a step you missed in your explanation that would make the approach more clarifying is to mention explicitly that you want to use each bit to represent whether a certain character has been seen, and that you use the character's ordinal representation modulo 32 to determine the index of the bit this information is stored in. I think it's worth remarking that you can only do this because all the characters in your input are adjacent in their ordinals and there is less than 32 of them (or else you'd get position clashes).

  • @bionh
    @bionh6 ай бұрын

    Thanks for the awesome content! Minor quibble: left shift always increases by the base, in binary that’s 2, not 10, it just looks like you multiply by 10 because the only digits in the numbers are 1 and 0

  • @Yupppi
    @Yupppi4 ай бұрын

    I love this style of rust. It looks pretty confusing at first sight but it's much better than for loops with random looking operations. The algorithms kick ass. And the browsing through at low level was pretty neat as well. It's pretty wild to consider how a human would just look at the 15th value and say "I've seen that already" instead of comparing all of them individually. Despite being pretty slow at some things, human brain just keeps amazing with all its optimizations. The Perez algorithm was really cool, I only recently saw it explained somewhere but I didn't understand it originally nor did I remember it. What surprises me is that it isn't part of standard algorithms.

  • @JerryThings
    @JerryThings Жыл бұрын

    I just started learning about hash tables, and immediately saw incredible performance boost. I would have never imagined that an array or a vector could do the trick

  • @Winnetou17

    @Winnetou17

    Жыл бұрын

    If you can use arrays, they are always the fastest

  • @kevindication
    @kevindication Жыл бұрын

    Hey man I’ve been really enjoying your content. I’ve been developing since 1994 and just came across your channel and have spent quite a few hours listening to you. Especially enjoying the friendly controversy with Theo. Ha! Also, awesome stache. Keep on keepin on.

  • @johnmccarty6989
    @johnmccarty6989 Жыл бұрын

    I actually look forward to watching your videos... something rare for me on youtube nowadays

  • @oblivion_2852
    @oblivion_2852 Жыл бұрын

    I like the comments about the order of hashing. I think in university alot of the time they fail to mention the constants in the complexity conversation and you often end up with people always thinking hashmaps and sets being the fastest completely unaware of the cost of hashing and the common list iterator for collisions.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    When I went to university, hash sets didn't even have linked lists inside of containers. We actually used linear and exponential back off to determine it's insertion location. It's a neat improvement to how much space you need for a set, and it also seems pretty fun to implement.

  • @oblivion_2852

    @oblivion_2852

    Жыл бұрын

    @@ThePrimeagen there's a cpp con lecture about googles flat hashmap implementation I watched years ago that was pretty interesting in terms of the decisions they made with writing a faster implementation. One of their optimizations was to use no pointers at all so once the hash gave an address you would just iterate across the key value pairs till you found your equality. On average you wouldn't need to iterate across many elements.

  • @TehKarmalizer

    @TehKarmalizer

    Жыл бұрын

    Implementation details matter. It’s important to have a rough idea how data structures work to understand the performance implications.

  • @nickadams2361
    @nickadams2361 Жыл бұрын

    Great stuff, a lot of fun stuff happens at the bit and byte level

  • @marcotinacci5718
    @marcotinacci5718 Жыл бұрын

    David's version is a clever use of the Boyer-Moore heuristic of good suffix for string pattern matching

  • @superchillh3o
    @superchillh3o Жыл бұрын

    savage. went from web dev to game dev in 7 steps. blazingly fast indeed, ty for sharing sir!

  • @micalevisk
    @micalevisk Жыл бұрын

    thank you for this blazing fast series.

  • @filipebraganca2558
    @filipebraganca2558 Жыл бұрын

    Wow! That one I'll need to reawatch a bunch of times to get what's happening on those improvements.

  • @JosephHenryDrawing
    @JosephHenryDrawing Жыл бұрын

    this is super interesting, upload more content like that!

  • @Starckoo
    @Starckoo Жыл бұрын

    Appreciate you King 👑

  • @Zzznmop
    @Zzznmop Жыл бұрын

    I know I’ve seen you do this many times, but I think it would be SUPER cool to see you do the setup and generation of stats/graphs for perf. The more I perf test, the more I see people are often optimizing for the wrong things

  • @RHCPhooligan
    @RHCPhooligan Жыл бұрын

    More technical videos on algorithms. This was fantastic

  • @brightonsikarskie8372
    @brightonsikarskie8372 Жыл бұрын

    This is amazing thank you

  • @alexIVMKD
    @alexIVMKD Жыл бұрын

    Good content Prime, amazing stuff

  • @fabianspecht7209
    @fabianspecht7209 Жыл бұрын

    love optimization Videos! Good one :)

  • @eula9
    @eula9 Жыл бұрын

    MORE OF THIS!!! luv u

  • @vantageous9217
    @vantageous9217 Жыл бұрын

    This was cool! More content like this please.

  • @seikatsu_ki
    @seikatsu_ki Жыл бұрын

    The greatest video I ever seen in KZread, Well Done Captain!

  • @RealLordy
    @RealLordy6 ай бұрын

    I use this bit manipulation to store a series of flags as a DWORD to keep track of e.g. user configurations in a database. Much more efficient than storing a zillion of true/false fields. Never thought about using it to compare hashes. Good one 😁

  • @Jovanovic91
    @Jovanovic91 Жыл бұрын

    You are presenting everything with such an ease, and it is highly understandable to me, self-taught (no university degree) DevOps engineer. If you were my teacher in high school I would be probably working for NASA or Roskosmos now... Make a course related to Rust development, Rust for beginners or similar...

  • @JoshDarling
    @JoshDarling Жыл бұрын

    Oh wow thank you, this opened my eyes to much.

  • @loicgrossetete9570
    @loicgrossetete9570 Жыл бұрын

    My mental try before the video ended at the one from David a perrez, cool optimization problem :)

  • @mariofleischmann1843
    @mariofleischmann1843 Жыл бұрын

    This video shows perfectly why I love writing high performant code. You get to be creative: Use your existing knowledge, e.g. the Boyer Moore algorithm for string matching, to come up with solutions for new problems. Know the internals of the underlying system to select the right data structures. All theory aside, you have to actually test and experiment. Measure something odd? Then fire up that compiler and check the assembly. It just never gets boring!

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    Most exciting

  • @aleclowry7654
    @aleclowry7654 Жыл бұрын

    “Binary ten thousand” is a phrase that makes be very uncomfortable. Lol

  • @pauloffborba
    @pauloffborba Жыл бұрын

    Great content. 🙏🏻

  • @mti2fw
    @mti2fw Жыл бұрын

    Nice tricks. I would appreciate a video like that but optimizing multiple network calls like an api gateway

  • @joaomachado9105
    @joaomachado9105 Жыл бұрын

    love this blazingly fast themed videos 😂

  • @Dani004able
    @Dani004able7 ай бұрын

    kind or tempting to try it in assembly now :D

  • @LiliumAtratum
    @LiliumAtratum7 ай бұрын

    The idea of iterating from the back of the window reminds me of the Boyer Moore algorithm for substring search.

  • @anmolsharma4049
    @anmolsharma4049 Жыл бұрын

    Your understanding of concepts always amazes me. I just got off learning JavaScript and now learning c++ and data structures for job placement but my true goal is to be like you. Have a deep knowledge of code and write blazingly fast solutions.

  • @codesymphony

    @codesymphony

    Жыл бұрын

    blazingly fast is fun, but it's really all not that important in the workforce

  • @epicgameryt4052

    @epicgameryt4052

    Жыл бұрын

    @@codesymphony it depends on who you work for. in my job having to process 50+ million records does require inner knowledge to deliver better experiences

  • @earthling_parth

    @earthling_parth

    Жыл бұрын

    @@epicgameryt4052 Correction to symphony's comment: *not that important in the majority of the workforce.

  • @TehKarmalizer

    @TehKarmalizer

    Жыл бұрын

    @@earthling_parth not sure I agree. The fact that front end developers have a reputation for being less educated on CS fundamentals doesn’t excuse the utility of knowing them.

  • @PatalJunior

    @PatalJunior

    Жыл бұрын

    @@TehKarmalizer Games is a great example, programmers used to rely on fast and optimized code to the game even run, nowadays it seems that it as shifted and more and more optimized garbage shows up every day.

  • @EmielvanGoor
    @EmielvanGoor Жыл бұрын

    I didn't understand most of it but still loved the video! Thanks!

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    well howdy! you will some day :)

  • @adevopsguy9517
    @adevopsguy9517 Жыл бұрын

    Awesome video, this was incredibly cool

  • @TehKarmalizer
    @TehKarmalizer Жыл бұрын

    The array solution is the one I would have come up with, but I think there may be a little room for improvement there, depending on what the compiler is already doing with that code.

  • @matteyas
    @matteyas Жыл бұрын

    In Julia, the naïve solution (using Sets and moving window just +1) runs in 7-8ms and the fast solution in 7-8µs on chars, or ~3µs if the input is already bit states. (Didn't bother doing a threaded version.)

  • @matthewg5792
    @matthewg5792 Жыл бұрын

    this was awesome. more please

  • @john_hawley
    @john_hawley Жыл бұрын

    Yes 2023 off to a great start. These videos are the secret sauce to this channel in '23 🔥

  • @JacobCanote
    @JacobCanote Жыл бұрын

    Woosh. A joy to see!

  • @thriceborn7665
    @thriceborn7665 Жыл бұрын

    Blazingly fast, indeed. Love this channel

  • @FastFSharp
    @FastFSharp Жыл бұрын

    Instant like for performance optimization content!!🎉

  • @Guilherme-qk9so
    @Guilherme-qk9so Жыл бұрын

    dude that was so sick!!!

  • @bozhidaratanasov7800
    @bozhidaratanasov7800 Жыл бұрын

    Hi, love your content! Can you share your thought process behind the use of excel and how you populate the data there?

  • @alangamer50
    @alangamer506 ай бұрын

    I love the pipeline from 3 line solution to x86 assembly

  • @massimilianocadeddu2351
    @massimilianocadeddu2351 Жыл бұрын

    man you just say "blazingly fast" and i automatically click the like button.

  • @rutabega306

    @rutabega306

    Жыл бұрын

    omg i just realized i did that too

  • @badhreeshmrao609
    @badhreeshmrao609 Жыл бұрын

    This is absolutely fascinating. I’ve a few questions: 1) How does one goes about developing these fast solutions? In order words, how does one learn to develop the skill of algorithmic thinking? 2) There’s always a tradeoff between performance and readability. So how realistic is it to use the fastest solution in a real world code base?

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    1. well you have to determine if the speed up is meaningful something simple as "just because its O(1) doesn't mean its fast" is a great thing to remember. Experiment to find what makes a difference

  • @georgehelyar

    @georgehelyar

    Жыл бұрын

    For a real code base, you write your code in a readable way, then measure it. If it's not fast enough, find where it's slowest in the hot path and make that bit faster. Repeat until it's fast enough.

  • @atiagosoares

    @atiagosoares

    Жыл бұрын

    @@ThePrimeagen I think that a good take that big O notation is not about whether an algorithm is fast or slow. It is about if it scales. A O(n) solution that is slow but viable at small scales will continue to be slow and viable at large scales.

  • @AquaEBM

    @AquaEBM

    Жыл бұрын

    1) Never stop programming new things/projects. This will challenge your intuition and improve it. 2) It depends on the use case. When performance is critical, readability is sometimes sacrificed, though this can be mitigated by, for example, using comments explaining what's going on. However, it's often more encouraged to prioritze readability when performance isn't a concern, so as to make the code easier to scale

  • @sdtok527

    @sdtok527

    Жыл бұрын

    @@georgehelyar This, or see if you can abstract the problem to a more general problem where optimizations are already known. An easy example example: sorting characters can be abstracted to sorting numbers, and sorting algorithms for numbers are well known.

  • @sheikhrachel
    @sheikhrachel Жыл бұрын

    Ok but that's like one of the best layman breakdowns of bit manipulation I've seen

  • @aflous
    @aflous Жыл бұрын

    Wow this one was excellent!

  • @loliveira
    @loliveira Жыл бұрын

    The David solution resembles the Boyer-Moore string-search algorithm. Nice video!

  • @erikp6614
    @erikp6614 Жыл бұрын

    Using DAP:s method with c, single threaded, takes about 7 ms on an old i7-3770S. If the input strings are the same (the one in the source file), it is about twice as fast as the best results in results_thread_ripper.csv. However using openMP and pthreads only makes it slower (much slower).

  • @emjizone
    @emjizone Жыл бұрын

    3:59 Well that's the way I do it by default, because I first learned to program with langages like _AppleSoft BASIC_ or _Turbo Pascal_ that had nothing like vectors or hash tables unless you implemented them yourself. I often fell more comfortable with verbose explicit index computation and loops than with more concise syntax calling automated objects or structures which are implemented in ways I can't always remember.

  • @nikensss
    @nikensss Жыл бұрын

    Wow, amazing stuff. I love this type of content.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    excellent!

  • @RobinCawthorne
    @RobinCawthorne Жыл бұрын

    "just below the like button" 😂 awesome video! not sure if i fully understood it all. still blew my mind though anyway. lol

  • @qodesmith520
    @qodesmith520 Жыл бұрын

    You make my brain hurt... in the most pleasing way possible.

  • @AlecMaly
    @AlecMaly Жыл бұрын

    Great content!!

  • @equenos
    @equenos Жыл бұрын

    Honestly I expected to see a mind-bending mathematically motivated algo but this is still very impressive

  • @lamprospitsillou6325
    @lamprospitsillou6325 Жыл бұрын

    More of this please!!

  • @SownJevan
    @SownJevan Жыл бұрын

    Another upload. You love to see it.

  • @ThePrimeagen

    @ThePrimeagen

    Жыл бұрын

    yaya!

  • @dandymcgee
    @dandymcgee22 күн бұрын

    The going backwards to skip large number of characters was likely inspired by the Boyer-Moore string-search algorithm, which is also what powers "grep". It's actually faster to grep for long strings than it is to grep for short strings because of this optimization. Longer search strings let you skip faster.

Келесі