Scaling One Million Checkboxes

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ย. 2024

ความคิดเห็น • 545

  • @Jutastre
    @Jutastre 3 หลายเดือนก่อน +1972

    Just make a microservice for each bit

    • @simo_the_goat
      @simo_the_goat 3 หลายเดือนก่อน +39

      😂

    • @NotMarkKnopfler
      @NotMarkKnopfler 3 หลายเดือนก่อน +212

      Yes. And make sure each microsevice is on a different machine. For performance reasons. And have them persist to a database. One database. On one machine 👌

    • @akshay-kumar-007
      @akshay-kumar-007 3 หลายเดือนก่อน +9

      LMAO

    • @lucasa8710
      @lucasa8710 3 หลายเดือนก่อน +9

      Actually so F funny

    • @TonyDiCroce
      @TonyDiCroce 3 หลายเดือนก่อน +11

      With a map reduce job for the state

  • @themilkman3118
    @themilkman3118 3 หลายเดือนก่อน +681

    Every checkbox checked spins up a docker container.

    • @Gregzenegair
      @Gregzenegair 3 หลายเดือนก่อน +18

      That's what I call microservices

    • @phosgene87
      @phosgene87 3 หลายเดือนก่อน +3

      And every pod spins up a node.

  • @bass5601
    @bass5601 3 หลายเดือนก่อน +331

    "Bytes are stored in the balls, right next to the microplastics-"

    • @gorlix
      @gorlix 3 หลายเดือนก่อน +8

      pee is stored in the balls in the balls

    • @mohammaddev6227
      @mohammaddev6227 3 หลายเดือนก่อน

      You can experience the ultimate challenge with 8 billion checkboxes with flags on my website : www.playstd.com
      please support me

  • @JGComments
    @JGComments 3 หลายเดือนก่อน +291

    Imagine creating a small site that hits the mainstream media.
    Marketing: That would be GREAT!
    Engineering: That would be AWFUL.
    All you need to know right there.

    • @TremereTT
      @TremereTT 3 หลายเดือนก่อน +7

      and it only cost 2 man-weeks in engineering .

    • @NickTaylorRickPowers
      @NickTaylorRickPowers 3 หลายเดือนก่อน +3

      Accounting: and we're fucked if that's on AWS or Microsoft servers

    • @JGComments
      @JGComments 3 หลายเดือนก่อน

      @@NickTaylorRickPowers Ugh, lol, brings up bad memories. We went through a phase where we moved to an enterprise agreement with MS, and everyone in IT moved their existing Excel forms, Access databases etc. to SQL server. MS hit us with a $2 MM true up that the business didn’t expect. That went over about as well as you’d imagine…

  • @Titere05
    @Titere05 3 หลายเดือนก่อน +539

    The establishment: There's no way society wouldn't crumble if we reduce working hours by 1 hour per day
    The world's population during work hours: checking boxes

    • @monad_tcp
      @monad_tcp 3 หลายเดือนก่อน +25

      The establishment : you have to work.
      How many humans actually work producing the food we eat : 3%

    • @TehKarmalizer
      @TehKarmalizer 3 หลายเดือนก่อน +6

      @@monad_tcp used to be everyone getting food all the time. Specialization is the reason we are where we are as a species.

    • @Name-qf6lr
      @Name-qf6lr 3 หลายเดือนก่อน +8

      @@monad_tcp if food is all you need you can just leave this complicated and arguably shitty life for a much simpler agricultural life

    • @Diddz
      @Diddz 3 หลายเดือนก่อน

      the visualization of cooperate PR and "pledges"

  • @MadJako77
    @MadJako77 3 หลายเดือนก่อน +41

    I really appreciate how you brainstorm how things could be done before learning how the author actually did it. Really a good way to teach and really interesting to see the different ways to approach the problem.

    • @XxZeldaxXXxLinkxX
      @XxZeldaxXXxLinkxX 3 หลายเดือนก่อน +2

      It's a good learning strategy in general. When I'm watching something like a course, I'll pause before a problem, try to solve it myself, and see why I'm an idiot and why the shown solution is better.
      It helps with both engaging with the material and practicing your own problem solving.

  • @BudgiePanic
    @BudgiePanic 3 หลายเดือนก่อน +93

    The fact that some nerd tried to DDOS the silly check box website

    • @ILoveTinfoilHats
      @ILoveTinfoilHats 3 หลายเดือนก่อน +28

      Average redditor

    • @chonkydog6262
      @chonkydog6262 3 หลายเดือนก่อน

      Lol i know the person that did that

    • @Kynatosh
      @Kynatosh 3 หลายเดือนก่อน +8

      I would have tried to spin up some bots to click on the checkboxes but that would have ddos'd the thing too

    • @MCasterAnd
      @MCasterAnd 3 หลายเดือนก่อน +2

      @@Kynatosh we were literally 50 people in a discord server doing this. I had 55 servers. Called in sick to work so I could check more boxes lmfao

    • @XDarkGreyX
      @XDarkGreyX 3 หลายเดือนก่อน

      There are plenty of basement dwellers who feed off of schadenfreude.

  • @Eysvar
    @Eysvar 3 หลายเดือนก่อน +61

    After watching through this whole thing, I can't help but be reminded of the write ups that Reddit did for r/place. The most interesting/technical one was for the 2022 version where they talk about doing a lot of these same things. "I-Frame" updates with websockets for difference updates, managing how to store the data in the backend, and even a little bit about scaling at that level.
    What I like about this article though, is that it's just one dude with some help from a couple of friends. It's much more of a feel good story than when a corpo does something similar.

    • @psychoedge
      @psychoedge 3 หลายเดือนก่อน +1

      "is that it's just one dude with some help from a couple of friends. It's much more of a feel good story than when a corpo does something similar."
      To be fair, I doubt more than one lead engineer and a few others were working on the r/place architecture. So the scale of people is roughly the same, the resources and personal network to gain information/skills you lack in the moment are just vastly different. Also projects like r/place are supposed to not fail, which definitely needs a lot more thought in advance. That being said the process that the author here described of learning how and why your scaling breaks step by step like you learning to understand your own code feels definitely more personal than corp essays.

    • @tbuk8350
      @tbuk8350 2 หลายเดือนก่อน

      @@psychoedge Yeah, it's different in some ways, but similar in the scale of the project. The key difference with r/place is that Reddit being a massive company has the money to front any bandwidth and server costs, so they didn't have to worry nearly as much about the cost of the overall project and could focus more on pure performance. If you're just one person fronting all the costs, you have to be a lot more focused on how much your implementation is going to cost you, and less about how performant you can possibly make your implementation.

  • @DavidGrossNYC
    @DavidGrossNYC 3 หลายเดือนก่อน +43

    I’m gonna be honest…. I’m feeling out of the loop because this is the first I have heard of this lol.

  • @wreigh6271
    @wreigh6271 3 หลายเดือนก่อน +257

    plot twist: brown hat hackers == cloudflare security (sales) team

    • @Exilum
      @Exilum 3 หลายเดือนก่อน +8

      I mean, he likely used the free cloudflare plan, so it wouldn't even count as sales

    • @Kenionatus
      @Kenionatus 3 หลายเดือนก่อน +7

      I give that one a 20% chance of being true.

    • @crimiusXIII
      @crimiusXIII 3 หลายเดือนก่อน

      "Hi, we noticed your site getting a LOT of traffic. Sign up for the premium plan now at $130,000 or we shut you down."😈

    • @gwentarinokripperinolkjdsf683
      @gwentarinokripperinolkjdsf683 3 หลายเดือนก่อน +2

      ​​@@Exilumwooshy

    • @Exilum
      @Exilum 3 หลายเดือนก่อน +2

      @@gwentarinokripperinolkjdsf683 whoosh only works on full on jokes, not when there are clear undertones.

  • @jacobblomquist5288
    @jacobblomquist5288 3 หลายเดือนก่อน +25

    What I would have done.
    1. Put the "entire page data" endpoint behind a CDN with a ttl of 1 second. That way your app server only gets 1 request for the entire state per second and the cdn handles scaling and distribution.
    2. Perform delta updates via websocket, also sending a checksum across. If after the delta is applied the check sums don't match, fetch from cdn again.

    • @DogeMultiverse
      @DogeMultiverse 3 หลายเดือนก่อน +2

      thats a great idea. maybe ttl of 5 or even 10 seconds would make more sense.

    • @JoshMutia
      @JoshMutia 3 หลายเดือนก่อน

      interesting take

  • @MCasterAnd
    @MCasterAnd 3 หลายเดือนก่อน +4

    bruh
    we were drawing bitmap black/white images on the site, turning the 1mill checkboxes into a 1000x1000 canvas
    we had a discord server of a few dozen people doing this
    I eventually created my own infrastructure of 55 servers to quickly draw images. I spent all night from 11pm until 7am creating my own CI/CD system and checking boxes at an inhuman rate. The rate limit on OCMB was pretty tough, and it was per-ip, so I had to increase my IP count - thus the high amount of servers. Others managed to utilize about 2000 proxies which nearly nuked the site out of existence.
    this was fun.

  • @stjepandrenski5486
    @stjepandrenski5486 3 หลายเดือนก่อน +44

    This kind of content from prime is gold. Explaining simple stuff like a pro

    • @avwie132
      @avwie132 3 หลายเดือนก่อน +1

      The blog post is already easy. Prime just rehashes. This isn’t his content

    • @MrTeslaX
      @MrTeslaX 2 หลายเดือนก่อน

      He isn't, he read everything somewhere and just acting like he knows a lot about it.

  • @SloanStewart
    @SloanStewart 3 หลายเดือนก่อน +78

    Middle Management Simulator 2024

  • @shadowpenguin3482
    @shadowpenguin3482 3 หลายเดือนก่อน +160

    An easy optimization would be to just send 10k checkboxes at once. Anything not visible is not interesting to the user, so no need to send to full million to them

    • @pyrocentury
      @pyrocentury 3 หลายเดือนก่อน +17

      Essentially virtualization/windowing

    • @JGComments
      @JGComments 3 หลายเดือนก่อน +19

      And also batch process the clicks. Show the user an update on the boxes they check, but only update the other pages and totals by 1K increments or whatever.

    • @Kyle-do6nj
      @Kyle-do6nj 3 หลายเดือนก่อน +18

      The term you are searching for is : View Frustum Rendering

    • @Frostbytedigital
      @Frostbytedigital 3 หลายเดือนก่อน +36

      ​@@JGComments click batching doesn't really work because multiple users could click the same box multiple times between updates.

    • @TreesPlease42
      @TreesPlease42 3 หลายเดือนก่อน +2

      Yeah the 125kb could have been better optimized, seemed like a lot of the work went into the patches

  • @AlexeiDimitri
    @AlexeiDimitri 3 หลายเดือนก่อน +10

    The guy had a in-house server but uses a Cloud solution for DB. GENIOUS.

  • @naturallyinterested7569
    @naturallyinterested7569 3 หลายเดือนก่อน +9

    Do note that the bitset implementation requires neither divisions nor modulo. Because i / 8 == i >> 3 and i % 8 == i & 7, so the lookup would be const bit = (arr[i >> 3] >> (i & 7)) & 1; I believe.

  • @diegoaestrada-rivera1901
    @diegoaestrada-rivera1901 3 หลายเดือนก่อน +46

    I would like to mention something about the "bool" being 64 bits long. You are absolutely correct that it depends on which system it is, but the actual length itself depends on the implementation for the language. For example, C++ bool's are 8 bits long (a byte) because that is the smallest addressable size you can have.

    • @1vader
      @1vader 3 หลายเดือนก่อน +4

      Yeah, same in Rust and x86 CPUs in fact can read single bytes, just not single bits. I think he just misspoke and the overall point that there's no such thing as native bit arrays is ofc still correct.

    • @bgdgdgdf4488
      @bgdgdgdf4488 3 หลายเดือนก่อน

      32 bit ints still need to be aligned to 4 bytes. So chances are good your bool value takes up 4 bytes while only using 1.

    • @1vader
      @1vader 3 หลายเดือนก่อน +3

      @@bgdgdgdf4488 No, not in an array. In a struct, yes, if there are no other small types to fill up the rest, but Prime was talking about arrays.

    • @zitronenwasser
      @zitronenwasser 3 หลายเดือนก่อน +1

      @@1vaderEven in a struct, you may be able to "pack" all the members, forcing them to not have any alignment and be immediately after another in memory

    • @bgdgdgdf4488
      @bgdgdgdf4488 3 หลายเดือนก่อน

      @@1vader sure, but lets be real, how often do you actually need a large array of booleans anyway? I can't remember the last time I needed more than 1 per function

  • @hersenbeuker
    @hersenbeuker 3 หลายเดือนก่อน +36

    @ 9:44 -> Fake news! booleans in rust don't take up 64 bits, they take up 1 byte or 8 bits. A struct of 3 bools takes up 3 bytes
    You can test this by inserting the following in the rust playground:
    struct Bools {
    foo: bool,
    bar: bool,
    baz: bool,
    }
    fn main() {
    // Returns the size of a type in bytes.
    let size = std::mem::size_of::();
    assert_eq!(size, 3);
    }

    • @epicxtortionist
      @epicxtortionist 3 หลายเดือนก่อน +8

      Looks like it was written in JavaScript at that time and V8 is written in C++. A quick google search said that while a boolean yes takes up 1 byte, depending on alignment it can take up to 8 bytes on a 64-bit platform
      Edit: went back and listened to Prime here. Yeah he explicitly calls out Rust. He was wrong with your example above lol

    • @nateshrager512
      @nateshrager512 3 หลายเดือนก่อน +4

      Yea i thought i was going crazy for a second hearing this. That kind of overhead in Rust would make zero sense to me since memory is not quantized at word size.
      x86 has been byte-addressable for how long? Doesn't matter that they are being accessed in the CPU as 64 bits

    • @StealerSlain
      @StealerSlain 3 หลายเดือนก่อน +1

      Won't this be aligned up to 4 bytes though?

  • @sloppydoggy9257
    @sloppydoggy9257 3 หลายเดือนก่อน +8

    Shifting bits can be done quickly and efficiently because the ALU has a "Shift Register" which implements an extremely efficient bit shift operation.

    • @attilavs2
      @attilavs2 3 หลายเดือนก่อน +1

      Yep it's literally a less than single cycle operation natively (if you account for superscalar/ out of order exec)

  • @JGComments
    @JGComments 3 หลายเดือนก่อน +7

    The guy who made this is a genius. Almost as smart as the Banana guy.

  • @Apoque
    @Apoque 3 หลายเดือนก่อน +15

    Brother, bool is only 8 bits, not 64. The only time wastes that much space is if you're doing something like (u64, bool) which would take a total of 128 bits due to alignment and padding.

  • @dllsmartphone3214
    @dllsmartphone3214 3 หลายเดือนก่อน +100

    reminds me of the one million dollar website 😂

    • @prajnaparamitahrdaya
      @prajnaparamitahrdaya 3 หลายเดือนก่อน +12

      It revealed your age

    • @dllsmartphone3214
      @dllsmartphone3214 3 หลายเดือนก่อน +5

      @@prajnaparamitahrdaya damn it... you got me :-)

    • @YadraVoat
      @YadraVoat 3 หลายเดือนก่อน +2

      The naming reminded me immediately.

    • @willhleucka821
      @willhleucka821 3 หลายเดือนก่อน +1

      Same vibes for sure

    • @aakaatram905
      @aakaatram905 3 หลายเดือนก่อน

      Yes first thing that comes to mind, late 20s is the age

  • @ramnewton
    @ramnewton 3 หลายเดือนก่อน +19

    I had a feeling prime would take this and spin into an hour long video. Not complaining though :D

  • @kralomoc
    @kralomoc 3 หลายเดือนก่อน +6

    When he talks about using bitset, I'm pretty sure he means something like this --
    A single byte is represented by 8 bits: 0000 0000
    Each bit can be represented in-place as the decimal version of the 1 byte value: 64 = 1000 0000 // 8 = 0000 1000 etc
    You can "set" or "get" a boolean value (represented by a single bit) from this "array" of bits using bitwise ops and that single byte value to represent the place for the bitflag. That means you can effectively store 8 boolean values with just a single byte. A checkbox is a boolean value in this case. So you can get 8 checkboxes into a single byte. Hope this clarifies.

    • @dealloc
      @dealloc 3 หลายเดือนก่อน +2

      Yes that is what a bit set is.

    • @attilavs2
      @attilavs2 3 หลายเดือนก่อน +1

      You are right in the principle, but not on the values
      0b10000000 = 128 or -128 depending on signedness
      0b00001000 = 8
      To simplify, you can memorize hex :
      0x0 -> 0b0000
      0x1 -> 0b0001
      0x2 -> 0b0010
      0x3 -> 0b0011
      0x4 -> 0b0100
      0x5 -> 0b0101
      0x6 -> 0b0110
      0x7 -> 0b0111
      0x8 -> 0b1000
      0x9 -> 0b1001
      0xA -> 0b1010
      0xB -> 0b1011
      0xC -> 0b1100
      0xD -> 0b1101
      0xE -> 0b1110
      0xF -> 0b1111

    • @kingcode420
      @kingcode420 8 วันที่ผ่านมา

      bitset.js you can read in the imp

  • @kylekinnear8878
    @kylekinnear8878 3 หลายเดือนก่อน +3

    This might actually make a great interview question for Senior Engineers.

  • @arsenbabaev1022
    @arsenbabaev1022 3 หลายเดือนก่อน +50

    9:48 he really just said that? Struct with 3 bools is 3 bytes in size with align of 1.

    • @johndoe-j7z
      @johndoe-j7z 3 หลายเดือนก่อน +21

      Depends on if there's padding but yes. I think Prime got a little confused.

    • @rcoder01
      @rcoder01 3 หลายเดือนก่อน +10

      @@johndoe-j7z There won't be padding because bools have an alignment of 1 byte on every common architecture

    • @soggy_dev
      @soggy_dev 3 หลายเดือนก่อน +9

      Yeah I think he confused himself because the chatter was making him short circuit lol. The other stuff was bang on though

  • @Seraph120
    @Seraph120 3 หลายเดือนก่อน +1

    Brown Hat! What a designation (do refrain from visually imagine that). Will adopt

  • @hipertracker
    @hipertracker 3 หลายเดือนก่อน +39

    There is also 2 million checkboxes in Elixir

    • @omerdvir1709
      @omerdvir1709 3 หลายเดือนก่อน +1

      LOL

    • @serpent213
      @serpent213 3 หลายเดือนก่อน

      Go Elixir! 😁

  • @ure4880
    @ure4880 3 หลายเดือนก่อน +12

    b-frames (past future frames/pixels) are just content that didn't change between 2 frames or at least didn't change too a degree where they'd be included in a p-frame. During streaming that would be your static images/banners or your mic.

    • @Postman00
      @Postman00 3 หลายเดือนก่อน +4

      That's not correct. The data in P & B-frames contain both full macroblocks (image data), and predicted macroblocks that describe the difference between it and the macroblock it is referencing from another frame (in the form of motion vector). They require other frames it references to already be decoded and stored in memory in order to fully reconstruct the image. The difference between P (predicted) & B (bi-predicted) frames is that P-frames can only reference prior frames, while B-frames can also reference future frames.
      This is the reason why IPB codecs are much more computationally heavy than if you only use P-frames, which in turn are computationally heavier than an All-Intra codec. In addition, depending on how many frames ahead or backwards you allow the encoder to reference, you will need more compute to encode or decode your video.
      In addition, depending on the codec, all frames may reference itself. Meaning if you have an exact repeating pattern, it may only need to have one macroblock of it.

  • @srijanraghavula
    @srijanraghavula 3 หลายเดือนก่อน +2

    watching prime react to anything makes it 100x better

  • @chasep9440
    @chasep9440 3 หลายเดือนก่อน +1

    Prime makes a 49 minute video about scaling 1 million checkboxes. Liveview does it with no scaling at all. Elixir on top as usual.

  • @JebacPresretac101
    @JebacPresretac101 3 หลายเดือนก่อน

    I've been responsible for maintaining a startup with exactly this infrastructure (r5+node+redis+mongo) for chatting with 10-15k paying subs, but I did not develop it, I was taking over with a new team after the startup was about to go bankrupt (bought out). This is how it's done in the real world too boys! But as I have not developed it, but took it over, I 2x or 3xed my ~10 years of commercial dev exp (20 total) just by watching this video.
    All the things I did as a gamedev/frontend/backend just neatly tying into a single thing. Nice.

  • @alexmipego
    @alexmipego 3 หลายเดือนก่อน +37

    14:05 - I'm unsure Redis makes sense here… if your entire app lives on 1 or 2 instances on the same machine, then all Redis does is add latency to an otherwise simple operation/sharing of data.

    • @veritas7010
      @veritas7010 3 หลายเดือนก่อน +5

      he doesn't do software ofc he can't understand that the way to do this is either a queue or a ha-dr store + algorithmic optimization

    • @TreesPlease42
      @TreesPlease42 3 หลายเดือนก่อน +1

      Load balancing is good for QOL

    • @Masterrunescapeer
      @Masterrunescapeer 3 หลายเดือนก่อน

      Often still add redis for a single app if state matters so you can update the app without downtime (if I'm too lazy to have an actual DB/it's a just cache it thing for short term with temp user state).
      A vast majority of that time the latency doesn't have much impact, you're talking 0.15ms or so for a set request (piping is like 0.5ms), this is on my work laptop though, but figures shouldn't be too different. This is especially true as every checkbox is independent of the other and lost updates don't really matter as just needs to be remembered that someone set it to true (is ticked).

    • @alexmipego
      @alexmipego 3 หลายเดือนก่อน

      @@Masterrunescapeer Serializing a file and sharing the file is not an hard task either.
      Latency matters because we're talking about thousands of requests per second.
      I understand why you/we do it (using redis), but the truth is we keep adding dependencies that each adds complexity and bottlenecks… that sometimes we could just did the work ourselves, spend the same time on it, but still get a vastly superior app.

  • @rajaspoorna6405
    @rajaspoorna6405 2 หลายเดือนก่อน

    That was so much fun to listen to!
    Total adventure!!
    Absolutely worth it!

  • @isaacoppong5330
    @isaacoppong5330 3 หลายเดือนก่อน +1

    “This guy is gonna get hired” took me out. Nolen used to work for Jane Street!

  • @eddecimoni
    @eddecimoni 2 หลายเดือนก่อน

    i know next to nothing about software engineering. this is so entertaining, i'm learning a lot

  • @samantha-ki7fu
    @samantha-ki7fu 3 หลายเดือนก่อน

    I saw this article and started reading it, but my eyes glazed over and my brain wouldn't engage, despite being really interested i was just too tired. Reading through it with you and your commentary was so much better, thanks.

  • @fleetfoxx
    @fleetfoxx 3 หลายเดือนก่อน

    I recently had a personal project go semi-viral in a niche twitch community and had to deal with many of these same issues, from late night panic scaling to shit hat hackers. Thanks for covering this story.

  • @sarvangdave3646
    @sarvangdave3646 3 หลายเดือนก่อน

    I believe I will have to read this article multiple times to just understand everything fully. But that just shows how much this guy has learnt from this project

  • @cooper54729
    @cooper54729 3 หลายเดือนก่อน

    i dont know why i got recommended this video, i know nothing about web servers, but im enjoying every *bit* of this video.

  • @ignrey
    @ignrey 3 หลายเดือนก่อน +2

    "Bytes are installed in the balls right next to the micro plastic"
    TheOldPrimy, Ex FAANG engineer.

  • @theskyblockman
    @theskyblockman 3 หลายเดือนก่อน +17

    (Did not finish the video, just putting in what I think is the reasonable way to do it, if you knew you would need to scale) You could just give the initial state to the user, make the client send updated checkboxes to the server as it goes, and then every 5 seconds or smth like that giving back to every users a patch of what's been happening the last 5 seconds which you would display to the user for the next 5 seconds as if it is happening in real time, made me remember a bit how Reddit did r/place.

    • @abdullahyousuf8059
      @abdullahyousuf8059 3 หลายเดือนก่อน +4

      Although effective, but feels like cheating

    • @hatkidchan_
      @hatkidchan_ 3 หลายเดือนก่อน +6

      that's exactly what website was doing, except 10 times a second and not once every 5. Also it was sending full state once in a while just to be sure

  • @TheAndreArtus
    @TheAndreArtus 3 หลายเดือนก่อน +1

    For a bitset: you can mask the 6 (for 64 bit words, i.e. u64) lowest bits with AND (mask 63 or 0x3F) to get a bit address and right shift by 6 to get the array index. If the array is U8 both AND and shift would be 3 bits (mask 0x07, shift 3). You would, in a case like this, not want to address each bit individually you can use the U8 to do a lookup into an array or even a switch. You would treat the word as a block and read the all at once (8, or word size, checkboxes at a time).

  • @ImJustACowLol
    @ImJustACowLol 3 หลายเดือนก่อน +2

    Hey Prime, you were partially correct on one part.
    In C/C++ and most other languages, a struct of 3 booleans (or 1-8 booleans) takes up 64 bits on a 64 bit machine; 8 bits per boolean + padding to fill the struct to an aligned size. I don't know about Rust, but I strongly would suspect that Rust does the same.
    The CPU indeed has to read from memory with 64 bits at a time, so the entire struct is read at once. Accessing members of the struct is architecture and compiler dependent and it varies wildly what optimizations are done compile-time that affect how the underlying members are accessed.
    Storing 64 bits per boolean regardless of the amount of booleans in the struct would be a tremendous waste and would cause significant performance issues (think cache misses etc.).

    • @SimonBuchanNz
      @SimonBuchanNz 3 หลายเดือนก่อน +1

      Cache line is 64 bytes, not bits, so he's even wrong there 😔
      Rust bool also has 1 byte align and structures align to the largest member align, so no it's actually better on Rust (iirc most C impls default to a min 4 byte alignment)

    • @hwstar9416
      @hwstar9416 3 หลายเดือนก่อน

      @@SimonBuchanNz that's not true? in C a struct with bool has alignment of 1

    • @SimonBuchanNz
      @SimonBuchanNz 3 หลายเดือนก่อน

      @@hwstar9416 hmm, is that spec or implementation defined? I could easily be misremembering, too.

    • @hwstar9416
      @hwstar9416 3 หลายเดือนก่อน

      @@SimonBuchanNz the standard doesn't enforce a size nor an alignment for bool (or any other integer type).
      But it does say that bool has the lowest rank of all integer types:
      "The rank of bool shall be less than the rank of all other standard integer types"

  • @TheMxA_
    @TheMxA_ 3 หลายเดือนก่อน +1

    Every checkbox, creates the next gen javascript framework.

  • @Diddz
    @Diddz 3 หลายเดือนก่อน

    this is one big visual metaphor for companies pretending to care about safety or going green, checking boxes

  • @FireDragon91245
    @FireDragon91245 3 หลายเดือนก่อน

    myself recently dealing with processor architecture can say the smallest unit the CPU can handle is 8 bit for GPIs but there are specific x86 instructions that allow a operation on a singular bit so a vector could be posibleish
    but yes even that implimentation would not change the fact that pages, lines are read at a time not only a bit

  • @multivariateperspective5137
    @multivariateperspective5137 3 หลายเดือนก่อน +1

    YEeeeSsssss……. BROWN HATS!
    Epic

  • @dhkatz_
    @dhkatz_ 3 หลายเดือนก่อน +2

    Actual losers in the chat when he mentioned being an asshole and not a hacker. Like that Zeychin guy saying "Hey, some of us are both." 🤓🤓 Like what a loser

  • @NatoBoram
    @NatoBoram 3 หลายเดือนก่อน +1

    "I'm sorry they came in from Mastodon"
    Yeah that could explain why you're blocked by furries x)

  • @NathanaelNewton
    @NathanaelNewton 3 หลายเดือนก่อน +1

    Wait.. I've been watching the second Channel this whole time without knowing there was the first one 😮

  • @fishHater
    @fishHater 3 หลายเดือนก่อน +17

    42:23 “he’s also probably not a furry” rookie error on his part.

  • @robmckennie4203
    @robmckennie4203 หลายเดือนก่อน

    Prime needs to get serious "chatter, tell me how I'm overcomplicating this or admit you're trolling or you're banned" 😂

  • @ShadowJazo
    @ShadowJazo 3 หลายเดือนก่อน

    Wow, thats top Content. What a great rundown and so good written.

  • @lynnwilliam
    @lynnwilliam 2 หลายเดือนก่อน

    There is a Vector Array. It's basically an array that gets bigger and smaller as needed. Like a dynamic array .
    They are useful

  • @stefdevs
    @stefdevs 2 หลายเดือนก่อน

    Fighting the masculine urge to make 1 Billion Checkboxes

    • @le0t0rr3z
      @le0t0rr3z 2 หลายเดือนก่อน

      Did you see what the man has invested with proper limitations? One billion would be way worse xD

  • @Neura1net
    @Neura1net 3 หลายเดือนก่อน +1

    This was quite insighfull. Thank you

  • @Jebusankel
    @Jebusankel 3 หลายเดือนก่อน

    "taught the client" is the official style for commit messages in the Linux kernel

  • @michaeldeane4807
    @michaeldeane4807 3 หลายเดือนก่อน +1

    learning a ton from this simple little project

  • @rayrayray
    @rayrayray 2 หลายเดือนก่อน

    This is like listening to a junior engineer who just learned basic RLE concepts.

  • @phantomtec
    @phantomtec 3 หลายเดือนก่อน +1

    0:32 Its the Internet equivalent of bursting bubble-wrap...? ✌🏼💕

  • @i-use-4rch-btw
    @i-use-4rch-btw 3 หลายเดือนก่อน +1

    I just checked a whole bunch of boxes in the shape of the word “GYATT” lol

  • @jthweatt412
    @jthweatt412 3 หลายเดือนก่อน +16

    Server gives static webpage content. client randomly check and uncheck boxes to simulate other users. Nobody’s the wiser

    • @eliana993
      @eliana993 3 หลายเดือนก่อน +4

      Except if people figure it out and communicate with each other.

  • @TheSaintOMS
    @TheSaintOMS 3 หลายเดือนก่อน +1

    I can't even imagine getting any of my projects' flask server code picked apart by Prime. Zero optimization in most cases, but it works, lmao.

    • @DogeMultiverse
      @DogeMultiverse 3 หลายเดือนก่อน

      u need to go viral and wrote a technical article about it.

  • @torphedo6286
    @torphedo6286 3 หลายเดือนก่อน +3

    7:40 I had to store a giant 3d grid of 1-bit cells, and I did pretty much exactly this

  • @boppinggamer8571
    @boppinggamer8571 3 หลายเดือนก่อน

    And people still say "No need to scale it up to thousands of users when your only going to get 1 user."

  • @disabledmallis
    @disabledmallis 3 หลายเดือนก่อน +1

    9:28 "There is no such thing as a vector of bits" to this I ask, what do you thing *vectorization* on many modern desktop CPUs actually is? Theyre instructions made specifically for performing operations on **bit vectors** (and other vector types too for your add/subtract/etc) but your bitwise operations are still valid! I've seen resizable bit vector implementations specifically so these instructions can be optimally made use of!

  • @OrgiT
    @OrgiT 3 หลายเดือนก่อน

    I love how I have no programming knowlage outside of basic python yet im here, listening to Prime saying magic words and pretending I'm a big boy and who understands everything 😎

  • @puffinbasher
    @puffinbasher 3 หลายเดือนก่อน

    Just a side line about bitsets.
    In languages that support them (or at least the ones I have worked on) they are literally a pointer to the start of some assigned memory, then the bits are not set in the logical manner, but instead set up so that we can logic them out with a PEXT between the bit request index (appended to it's inverse) then an xor between the returned byte, the repeated request index, and some magic constant. It was an insane bit of dark arts maths, but it is truly static time.

  • @szirsp
    @szirsp 2 หลายเดือนก่อน

    16:00 On the update channel I would just send 64 bit (or maybe 32 bit) word updates with the word index (which is just 2 byte long), so 10 bytes (or 6). And if you can batch outgoing updates then array of these index, word records.
    With sending just 100 bytes you can update 10 sparse bit change to 640 bit change. With just 1 bit change you can sync 63 additional nearby bit.

  • @frozenphoenix1463
    @frozenphoenix1463 3 หลายเดือนก่อน

    Each checkbox turns on a physical server to store the bit

  • @keremardicli4013
    @keremardicli4013 3 หลายเดือนก่อน

    Best read of the year so far.

  • @suede__
    @suede__ 3 หลายเดือนก่อน

    Seems like a good usecase for learning how to use roaring bitmaps as well.

  • @robmckennie4203
    @robmckennie4203 หลายเดือนก่อน

    Tc is so wicked, ages ago i spent like a day reading the man page and trying out some of the interesting things it does

  • @NSA-admin
    @NSA-admin 3 หลายเดือนก่อน

    I like brown hat hacker. But you know that's essentially what hacking started as. Breaking it because it's fun and interesting to do. Although like you said the target matters so I think brown hat is applicable for yeah just personal neat projects and stuff especially single owner sites with essentially no sec infrastructure.

  • @forbiddenera
    @forbiddenera 3 หลายเดือนก่อน +1

    10:34 you dont have to use 64 bit registers exclusively on x86-64 IIRC..?

  • @donjohnson6063
    @donjohnson6063 3 หลายเดือนก่อน +2

    I don't think brown hacking was intentional , this started to become a game for people playing a game of king of hill

  • @bopon4090
    @bopon4090 3 หลายเดือนก่อน +1

    Man i got a lot to research from this

  • @CrowziYT
    @CrowziYT 2 หลายเดือนก่อน

    Take a shot for every box checked.

  • @m4rt_
    @m4rt_ 3 หลายเดือนก่อน +1

    6:40 I would assume that they would do something like this:
    u8 data[1000000 / 8] = {0};
    void flip(u32 index) {
    u32 offset = index / 8;
    u8 bit = index % 8;
    data[offset] ^= 1 > bit) & 1;
    }

  • @JMurph2015
    @JMurph2015 3 หลายเดือนก่อน +1

    Protobuf would go crazy here. The binary representation would be super easy and you can enable gzip compression over the wire trivially if I remember right. Protobuf with like ZeroMQ would be so fast here.

    • @MikhailBorisovTheOne
      @MikhailBorisovTheOne 3 หลายเดือนก่อน

      How would you do that in a browser?

    • @JMurph2015
      @JMurph2015 3 หลายเดือนก่อน

      @@MikhailBorisovTheOne Protobuf has a JavaScript library. One of its main use cases is gRPC which is browser -> server.

    • @MikhailBorisovTheOne
      @MikhailBorisovTheOne 3 หลายเดือนก่อน

      @@JMurph2015 Yea, maybe you are right. It probably uses websocket and sends binary data over it?

  • @Lord2225
    @Lord2225 3 หลายเดือนก่อน +1

    10:00 They meant specialization of vector that bit packs many bools into single adress. It is default in C++ vector and in rust there is so called bit-vec

    • @NibbleMeTwice
      @NibbleMeTwice 2 หลายเดือนก่อน

      Hey, I'm the guy who said "Vec with Bits" in the chat. Glad somebody knew what I was talking about.

  • @johanavril1691
    @johanavril1691 3 หลายเดือนก่อน +2

    man never heard of bitsets after 10 years of programming, things happen

    • @f.f.s.d.o.a.7294
      @f.f.s.d.o.a.7294 3 หลายเดือนก่อน +3

      BitSet is a standard class since Java 1.0, but I only noticed it a few years ago

    • @BridgeBum
      @BridgeBum 3 หลายเดือนก่อน

      ​@@f.f.s.d.o.a.7294And a python thing as well, but at the time Prime was thinking in terms of JS and saying there's no such thing with an implied "in JS" to his comments.

    • @askeladden450
      @askeladden450 3 หลายเดือนก่อน

      Its mostly used in memory constrained environments like embedded systems or even game engines. Each boolean only takes up 1 bit in a bitset, atleast with how its implemented in c++ standard.

  • @velkb228
    @velkb228 3 หลายเดือนก่อน

    bro be checking boxes

  • @agsystems8220
    @agsystems8220 3 หลายเดือนก่อน

    It is a set because ordering is not important. We are never going to want to loop through it in a way that depends on order, so calling it an array would be over specified. Additionally, we don't care about adjacency in memory, so it would be perfectly reasonable to separate it into chunks, and store them without hard layout constraints on them.
    It will be bit arrays somewhere down there, but it does make sense to hide it behind an abstraction. If you decide later that you need a specific implementation then you can build that without violating the specification of the bitset then you can do that without expecting other things to break.
    Also, while some of the brownhat stuff was definitely dickish (DDoSing is not clever or novel), the person that checked box 100 million might not have been. If Redis expanded that set to that size automatically with just one set, you would only need one person with QA instincts to try it once. That doesn't need malice.

  • @LittleRainGames
    @LittleRainGames 3 หลายเดือนก่อน

    A bool is 1 byte. A cpu can 100% read and write 1 byte.
    Some CPUs like AVR can do bit level manipulation too, but the instructions can only execute on certain address ranges, I believe on registers.

  • @MantasJurkuvenas
    @MantasJurkuvenas 3 หลายเดือนก่อน +1

    Lithuania mentioned!!! Woop woop!

  • @k0rnburn
    @k0rnburn 3 หลายเดือนก่อน

    D mentioned! one more time! For 2 videos in a row... dlang never has been such popular before

  • @AUATUWVSH
    @AUATUWVSH 3 หลายเดือนก่อน +12

    knowing bit math should be a mandatory prerequisite for all programming jobs.

    • @DogeMultiverse
      @DogeMultiverse 3 หลายเดือนก่อน

      laughs in UX designer

    • @PanosPitsi
      @PanosPitsi 3 หลายเดือนก่อน

      @@DogeMultiversehe said programming jobs 👀

    • @ManjotSingh-sf2ri
      @ManjotSingh-sf2ri 3 หลายเดือนก่อน

      cries in embedded systems design

  • @NeverSnows
    @NeverSnows 3 หลายเดือนก่อน +1

    5:27 wouldn`t it be better if we ignored single cases? So we would have 4W2JD or even ignore doubles, having the same lenght as 4WJJD

    • @kingcode420
      @kingcode420 8 วันที่ผ่านมา

      Slower reads

  • @NeilHighley
    @NeilHighley 3 หลายเดือนก่อน

    I'd like this as a informal coding challenge

  • @Kenbomp
    @Kenbomp 3 หลายเดือนก่อน +2

    Redus is overkill statically

  • @gardnmi
    @gardnmi 3 หลายเดือนก่อน +6

    I this is why falcor exists lol.

  • @HeneryGabliess
    @HeneryGabliess 3 หลายเดือนก่อน

    You guys are silly, firestore documents charge per read so use base 64 encoding to store checked state and index with ads to pay for the read write cost XD

  • @deventerprises2640
    @deventerprises2640 3 หลายเดือนก่อน

    In a DB make a state variable with 1,000,000 bits, whenever a checkbox gets toggled i.e. checked or unchecked. A request is sent to the DB about which bit to flip. Here for example if we send 34 then the 34th bit will toggle and a update would be broadcasted on all active devices giving them the data of 34. This prevents multiple read from the variable with 1,000,000 bits. This variable would only be read by the client side on initiation of the webpage or reload/refresh of it. you can duplicate the variable to attain a historical record and increment a counter for every request sent

  • @RamiAwar
    @RamiAwar 3 หลายเดือนก่อน

    I'm waiting for the Elixir rebuild of this site

  • @robonator2945
    @robonator2945 3 หลายเดือนก่อน +21

    9:50 I can find literally zero evidence for this assertion. Even looking online the worst case I can find people citing is that the LLVM will generally assign each boolean to an i1 and assign one byte to each boolean. I cannot find a single source corroborating that it assigns 64 bits to each boolean.
    C *_also_* generally assigns 1 byte to each bit as far as I'm aware but if you have a struct of several bits then they can share the same byte. I could be wrong on this, I never quite got a firm hold on packing bits, but I think this is the case. The reason Rust doesn't is (as far as I can tell)
    1 : because then they can't be referenced easily. (if you use other datastructures that forego this requirement they can pack bits in together) In theory I think this could be sidestepped in the compiler, but it'd be rather complex to add.
    2 : "it's complex, if you pack them like that it's slower because then to reference any individual bit you need to use bitshifts and bitmasks!" no, just, just no. This is just more "hur de hur premature opimiztion rut of ahl EVIL!" waffling. Realistically for most operations you'd only need to do a predetermined bitmask but even if you *_did_* need to do both a bitmask and a bitshift those are like the two fastest operations a CPU can possibly perform so the memory savings would dramatically overcompensate for any possible CPU slowdowns. Oh, also caching is a thing. Having them packed together would improve the spatial locality of the data thereby improving cache hits, making it faster. So, no, this is just wrong, stop saying it. What you mean by "premature optimization is the root of all evil" is "I'm too lazy and/or bad to write good code".
    3 : lack of demand given how much effort it'd take to make it happen, plus how easily sidesteppable it is with dedicated bitfield crates and such.

    • @SlexisSlacks
      @SlexisSlacks 3 หลายเดือนก่อน +1

      How do you avoid the bitshift? Rust only allows 1 to be recognized as `true` iirc

    • @Fedor_Dokuchaev_Color
      @Fedor_Dokuchaev_Color 3 หลายเดือนก่อน +6

      Yeah, bit fields in structures is a pretty common trick to use cache more effectively, AFAIK

    • @VivekYadav-ds8oz
      @VivekYadav-ds8oz 3 หลายเดือนก่อน +1

      C will put booleans in consecutive bits but only if you use the bitfield syntax (struct S { char x:1; char y:1; char z:1} __attribute__((packed));) and add the compiler attribute to pack them together.
      And why are you fighting invisible enemies? It's pretty obvious why Rust doesn't have it is simply because it's not that common of a usecase unless you're making very low-level communication protocols, so there isn't much need for it, it doesn't have to do with the fact that some (idk who) would consider it inefficient.

    • @isodoublet
      @isodoublet 3 หลายเดือนก่อน +1

      I don't do Rust but I'm pretty sure the correct value is 1 byte per bool, same as C++. Incidentally, in C++ a vector of bools is implemented as a bitset. Two comments on that choice:
      1. It's extremely fast.
      2. It's considered a grave mistake. It's nice that the standard library has a bitset type with a similar API as vector. It's not nice that it's literally a vector. If you index into an element of the vector (of any other type) you get a reference to that element, which is pretty much interchangeable with it for all intents and purposes. When you index into a vector of bools you get a proxy type that does the bitmasking for you. It's convenient, it's a fine api, but it's not a vector.

    • @isodoublet
      @isodoublet 3 หลายเดือนก่อน

      " if you have a struct of several bits then they can share the same byte. "
      Pretty sure this part is not correct. What is normally done is to pack for example, an i16 and two u8s in the space of a single u32. This generally depends on how the elements are ordered, since for example, if you did u8 i16 u8, the i16 would end up misaligned. Cpus can tolerate this, but it's slower, so compilers will typically add padding in that situation. In C++ you can opt out of this (to have a well-determined memory layout) with a pragma. No idea how it works in Rust. But I _can_ say that packing a bunch of bits into the same byte would require the same sort of bitmasking logic as in C++'s vector. Doable, but it _has_ to be opt-in. I would be shocked if Rust made the wrong choice here.

  • @sirgouki6207
    @sirgouki6207 2 หลายเดือนก่อน

    You could have easily explained it by referencing the C# BitArray struct. Bool in almost every language is at least the same size as char/u8, and BitArray is 8 of those ... 8*8 = 64 bits (8 bytes) to store 1 byte, and most programming languages do this similarly if they have a similar function. When I emulate 8bit and 16bit CPUs, I always use the relevant data type (u8 or u16) specifically for that reason - I've already got my word size available and I can just use boolean operators to get the value of the specific bit and go on from there.
    One thing you are missing though, is that no just because you're targeting x64 instead of something else, that doesn't automatically make the data type jump up. I target exclusively x64 in visual studio, my base int size is still 4 bytes (32 bit). And I didn't set it up to do that, it just came default that way for me. A CPU can and will pull increments of data, as long as it's not single bits (as you said), but it only pulls what it needs. An ASM instruction exists even now for grabbing 8 bits of memory in the ISA (this is why in programming languages, the smallest real data types are 8 bit - which reinforces what you were trying to say: there is no CPU instruction in any consumer ISA that pulls less than 1 byte of data), and this is what is run when your code is compiled.
    In both C++ and C# I have to manually use the 64 bit data types to make my ints hold that value, or change some compiler flags. Also, 64 bit CPUs can address 128bits of data. This isn't even new tech, as even the OG GameBoy, with its 8bit Z80 like cpu could address 16bit addresses, by combining two registers and treating them as one (which is, as far as I know, how current gen 64bit CPUs address 128bits). It's all dependent on what instructions are implemented at the hardware level.
    Edit: The C++ equivalent to C#'s BitArray is BitField. Although, instead of it being a struct of type Bool (which in C#, is itself a struct if memory serves... why I'll never know), it can be a collection of any integral type according to cppreference

  • @brianbarnes746
    @brianbarnes746 3 หลายเดือนก่อน

    I just found your TH-cam channel recently.. I enjoy all of your videos.. Very insightful.. Although I disagree with your opinion on AI.. I see AI taking over virtually all of IT, with minimal expansion of AI tech.. Your videos will be useful for contextual reference in AI models