The EASIEST Way To Optimize Your Code! | Roblox Studio

Поделиться
HTML-код
  • Опубликовано: 26 янв 2025

Комментарии • 145

  • @stewiepfing539
    @stewiepfing539  6 месяцев назад +32

    Do you guys like buffers?

    • @Jackinbox19001
      @Jackinbox19001 6 месяцев назад +2

      Nah idk, i wil think about it but i wont be needing buffers, my game is currently using under 1 mb of ram (It have at least 50 scripts)

    • @kekulusskek
      @kekulusskek 6 месяцев назад +3

      ​@@Jackinbox19001 it's useful in datastores tho, if i'm not wrong

    • @Jackinbox19001
      @Jackinbox19001 6 месяцев назад +1

      @@kekulusskek How?

    • @enpiesie
      @enpiesie 6 месяцев назад +1

      ​@Jackinbox19001, you can only store so much in a datastore key, so to conserve space you can compress it using buffers.

    • @Jackinbox19001
      @Jackinbox19001 6 месяцев назад

      @@enpiesie give me an example code

  • @defenestratorr
    @defenestratorr 6 месяцев назад +69

    This is a microoptimization that you probably won't need in like 99% of use cases. Unless you're working with big data or something

    • @ivymuncher
      @ivymuncher 5 месяцев назад +10

      i love using buffers for networking and datastores :-)
      even if it might be a micro optimization they make me feel good so i just use them anyways lmaoaoaoaoaooa

    • @swordlegend3256
      @swordlegend3256 4 месяца назад +5

      still very useful. and micro optimisations add up to something big so mine as well it takes like 10 minutes

    • @Testbot379
      @Testbot379 2 месяца назад +1

      I'm late but as per the recent editable images update, you can read and write pixels into the images by using a unsigned byte buffer (8 but u)

    • @zilezia
      @zilezia 2 месяца назад

      Even still it's good practice do be doing it this way

    • @imnotsplix2
      @imnotsplix2 3 дня назад

      @@zilezia not at all.

  • @jodio8071
    @jodio8071 6 месяцев назад +104

    The video is very informative and good but the only problem is that sometimes you're saying "bits" instead of "bytes".

    • @GattoBIN
      @GattoBIN 6 месяцев назад +4

      cry about that is a nice video 10/10

    • @bruhblox_
      @bruhblox_ 6 месяцев назад +60

      ​​@@GattoBINwhat's wrong with you, he just corrected him

    • @pyxelbuh
      @pyxelbuh 6 месяцев назад +30

      @@GattoBIN respectfully they corrected vital information that if not corrected could cause major confusion in new programmers

    • @GattoBIN
      @GattoBIN 6 месяцев назад +7

      @@pyxelbuh You got a point, true

    • @ana_s
      @ana_s 6 месяцев назад +5

      ​@@GattoBINwow angry much. The video got very important information wrong. What's wrong with correcting it for the sake of other people

  • @theosiris4179
    @theosiris4179 6 месяцев назад +19

    5:08 Unsigned and signed should be swapped. Unsigned takes only positive inputs, and will handle overflows and negative inputs by taking the modulo of the input number with its maximum number + 1. On the other hand, signed numbers allows numbers to have a negative sign. Overflowing a signed integer is trickier, as it involves first taking the modulo with max + 1 then using two's complement with the number in binary. Roblox handles overflows automatically.

    • @stewiepfing539
      @stewiepfing539  6 месяцев назад +1

      thats what I said 😭😭

    • @theosiris4179
      @theosiris4179 6 месяцев назад +6

      @@stewiepfing539 To clarify what I meant: Under the unsigned comments should be buffer.writeu and under the signed comments should be buffer.writei, not the other way around. It's a super small mistake.

    • @exolyne.
      @exolyne. 6 месяцев назад +1

      ​@@stewiepfing539 you wrote the opposite functions for what the code comments were saying

    • @Wyrmver
      @Wyrmver 6 месяцев назад

      modulo? dude it doesn't use modulo it's just how binary works

  • @overdsh_
    @overdsh_ 2 месяца назад +3

    They are useful for heavy algorithm, networking and serialization but it's kinda useless for anything else cause 99.9% of the devices can handle a few extra bytes fine

  • @bebleoklept
    @bebleoklept 2 месяца назад +3

    im using this for a loading screen, and its almost twice as fast now.

  • @danonek07
    @danonek07 3 месяца назад +1

    They are usefull for chunking games and creating render distance algorithms, they are very performant heavy sometimes

  • @Runtem
    @Runtem 5 месяцев назад +1

    Very nice library, I would probably use this in the future when I'm developing more complex games. Also this library is very similar to the one I used in Unity clicker games called PlayerPrefs which function similarly, however there were some limitations for data types and as far as I know, they couldn't store more than 1 piece of data in each variable.

  • @로좋
    @로좋 6 месяцев назад +1

    Thank you for notifyng me about buffers 😄❤️

  • @tiltedblock
    @tiltedblock 6 месяцев назад +2

    To be honest, on the other side using this make scripting/coding looks more complicated than usual

  • @Dr_mafario
    @Dr_mafario 6 месяцев назад +2

    Very cool stuff, though the back and forth and the random pauses make it sound so confusing

  • @Divine706
    @Divine706 6 месяцев назад +2

    Maybe, you can create a module with a buffer library?

  • @rocketpadgamer
    @rocketpadgamer 6 месяцев назад +2

    while I was watching this video I decided to go outside where the kittens were, I paused the video, but my headphones landed on the space bar, so the video was actually playing at 2x speed, I skipped most of the video because of this

    • @RyanEXElol
      @RyanEXElol 6 месяцев назад +1

      Watch it again💀💀

    • @noxinabox3506
      @noxinabox3506 6 месяцев назад +1

      Cool story bro.

  • @lalaly2011
    @lalaly2011 6 месяцев назад +1

    buffers should be used for compacting data that is sent over the network or you have big arrays
    using buffers for variables are unnecessary unless your going to send them to another script with a remote event (especially unreliableremoteEvents that have a 900 byte payload limit)

    • @rrb101567
      @rrb101567 6 месяцев назад +1

      im gonna assume buffers will be super useful in saving large inventories to the DataStores

  • @Hanselkek
    @Hanselkek 6 месяцев назад +3

    Ty :)

  • @KashTheKingYT
    @KashTheKingYT 6 месяцев назад +4

    W stewiepfing as always!

  • @Kitsune_Dev
    @Kitsune_Dev 6 месяцев назад +2

    while this is great for Basics, can you make a more in depth video on how to use this for mass data compression and decompression?
    concept is to automate it completely by detecting the type of data, compress it and map the order somewhere for decompression

    • @RyanEXElol
      @RyanEXElol 6 месяцев назад

      Basics help you in complex stuff, you can also read roblox documentations about it.

    • @InfinityChances_
      @InfinityChances_ 6 месяцев назад

      You could use for loops that take each ID of a table, adds it to the buffer, and continues. To get it back, take the length of the buffer, get a for loop, and pull each data out and put it in a table. I'm not fully sure but this should work

    • @exhydraboy2429
      @exhydraboy2429 4 дня назад

      @@InfinityChances_ I wouldn't use for loops unless it's truly unavoidable. Better approach would be to use a meta table and module script setup

  • @theoverlord3371
    @theoverlord3371 6 месяцев назад +23

    I like to gamble. how to gamble in studio

    • @pawjobsforbro
      @pawjobsforbro 6 месяцев назад +14

      math.random 🗣🗣🗣🔥🔥🔥

    • @CheeseY420
      @CheeseY420 6 месяцев назад +1

      print(Random.new():NextInteger(1, math.huge()))

    • @Mono_DevRBX
      @Mono_DevRBX 6 месяцев назад

      Random:NextInteger

    • @로좋
      @로좋 6 месяцев назад +8

      math.random Fr 🗣🗣🔥🔥🔥

    • @PixelOyuncuZ
      @PixelOyuncuZ 6 месяцев назад

      Random.new():NextInteger() 🤓

  • @Wayne2.
    @Wayne2. 5 месяцев назад +1

    How would I use this in a datastore though? using the read functions just returns the original string. Sorry if this is a dumb question, I just haven't fully understood bitbuffers yet.

    • @builderdolphin
      @builderdolphin 5 месяцев назад

      You can use buffer.tostring to save the data to a string, and buffer.fromstring to convert the saved string back to a buffer.

  • @ozzy1987
    @ozzy1987 6 месяцев назад +5

    I would *really* advise against using these because of how much of a micro-optimization they are unless it involves networking or serialization, and even then, only really consider it if your game or system is having problems in the first place.

  • @viperdune
    @viperdune 6 месяцев назад +1

    can buffers be used in datastores instead of tables?

  • @finjer5018
    @finjer5018 6 месяцев назад +3

    Cool video!

  • @Lobster305
    @Lobster305 6 месяцев назад +1

    just like coding with assembly

  • @Avysilvasan
    @Avysilvasan 6 месяцев назад

    guys i think buffer needs a nerf🥶🥶 shid so cold

  • @Kitsune_Dev
    @Kitsune_Dev 6 месяцев назад

    O M G yes thank you!! 🙏🏻

  • @furroy
    @furroy 6 месяцев назад +4

    hardly the easiest way to save memory. i'd rather down sample one 1024 image to 512 and prob save more than this with a lot less work!

    • @RyanEXElol
      @RyanEXElol 6 месяцев назад +3

      Umm actually the vid was about numbers and strings🤓

    • @robocat168
      @robocat168 6 месяцев назад +1

      @@RyanEXElol True. You should do everything in your power to save memory.

  • @garytodak
    @garytodak 6 месяцев назад

    i have tried to use this, but its hard. you need to think how big is the value, what type, and what index is the buffer, is it signed, unsigned, integer, negative?
    if it big value, is it 8,16? all these need to think. unless you have good understanding on how your game value is, dont use it. but the good thing is, we can have like the value cap to what the byte is. like if i use 16bit the number will be in 0-65536 and if i use this for my character coins, it wont go beyond that. so maybe its good for security? in case someone hack and want to set it to 9999999 which is not possible in 16bit.

    • @saltiodine
      @saltiodine 4 месяца назад

      bro just check if the value passes 65k lmao why you would user buffer for that xd

    • @saltiodine
      @saltiodine 4 месяца назад

      and it just will be possible to exploit your game if you let them to

  • @8tan200
    @8tan200 6 месяцев назад +1

    im sorry to be thet guy but how tf do you find these secret stuff?

    • @noobzyx5700
      @noobzyx5700 6 месяцев назад +3

      Its just that no-one uses it and can be easily replaced by the more simpler option which is a variable.

    • @yumiyumee
      @yumiyumee 6 месяцев назад +2

      devforum and roblox's documentation

    • @kryptonnslaxx6378
      @kryptonnslaxx6378 6 месяцев назад

      We studied about these in high school lol

    • @nanni5230
      @nanni5230 6 месяцев назад

      ​@noobzyx5700 Unless you are making a truly large scale game.

    • @windy6191
      @windy6191 6 месяцев назад

      @@noobzyx5700what do you mean replaced by variable

  • @ScriptifyLua
    @ScriptifyLua 4 месяца назад

    Why don’t people do this more often?

    • @imdeadiguess3505
      @imdeadiguess3505 18 дней назад

      Its mostly used for micro optimization, things like huge datas and etc etc, thats the reason, theres not alot of roblox games that have huge amounts of memory/data that needs to be compressed

  • @gamingwithlilabe3711
    @gamingwithlilabe3711 6 месяцев назад +1

    11-12 Hours, lol!

  • @salmanizzadin
    @salmanizzadin 6 месяцев назад

    📝

  • @marcoorozco9420
    @marcoorozco9420 6 месяцев назад

    YOU SAID 3.1415927 INSTEAD OF 3.1415926

    • @stewiepfing539
      @stewiepfing539  6 месяцев назад +2

      Thats what I meant in the video, single floating point numbers dont have the precision like double precision floating point ones

    • @erd404
      @erd404 6 месяцев назад

      3.14159265…
      You’d round up to 7 if you’re only going up to that digit.

  • @MarzFromMars
    @MarzFromMars 6 месяцев назад

    cool

  • @noon1263
    @noon1263 6 месяцев назад

    so apart from buffer, there is no other way to optimise your code?

    • @tantank
      @tantank 6 месяцев назад +2

      Obv, no

    • @noon1263
      @noon1263 6 месяцев назад

      @@tantank im convinced there is, we just don't know it yet.
      we are in this together amigo!

    • @Juju-dz5qt
      @Juju-dz5qt 6 месяцев назад

      Actor's, parallela roblox, OOP etc

    • @Juju-dz5qt
      @Juju-dz5qt 6 месяцев назад

      ​@@noon1263prob have other way's what i dont know

    • @noon1263
      @noon1263 6 месяцев назад

      @@Juju-dz5qt heard of Actor's before but haven't really looked into them.
      I'm not sure what you mean by "parallel roblox", do you mean connecting functions with the :ConnectParallel() function?
      Also not sire what you mean by OOP.

  • @ablueslime
    @ablueslime 6 месяцев назад

    hi

  • @lembarkii8669
    @lembarkii8669 6 месяцев назад +1

    this is cool but not really worth it or needed in this day and age

  • @tipic_faker4166
    @tipic_faker4166 6 месяцев назад

    lol

  • @I_pvn
    @I_pvn 6 месяцев назад +2

    dont do this

  • @fayking
    @fayking 6 месяцев назад +4

    this is probably being used in a really specific usecase, nice video btw

    • @abodReal
      @abodReal 6 месяцев назад

      Networking for sure

    • @fayking
      @fayking 6 месяцев назад

      @@epixerty yea, you can use it everywhere but its a bit overkill haha

    • @theosiris4179
      @theosiris4179 6 месяцев назад +1

      ​@@epixerty Just because you can use it everywhere doesn't mean you should. Variables without buffers allocate memory efficiently automatically. Buffers need the fixed amount of memory, and a little more to manage the buffer itself.
      Additionally, the steps to read & write buffers adds complexity to your code.
      local variable = 16 -- 4 bytes are used
      print(variable) -- Outputs: 16
      local mbuffer = buffer.create(4) -- Allocates 4 bytes + overhead memory for buffer management
      buffer.writei32(mbuffer, 0, 16) -- Writes an integer (4 bytes)
      local value = buffer.readi32(mbuffer, 0)
      print(value) -- Outputs: 16
      A better use case for buffers would be in data storage (datastores, memorystore) or networking, where they can handle large volumes of data efficiently.

    • @yumiyumee
      @yumiyumee 6 месяцев назад

      it's good for networking

    • @yumiyumee
      @yumiyumee 6 месяцев назад

      ​@@epixerty don't use buffers on everything