Jump to content
  • optimization o'clock


    andracass

    good morning.

    let's talk optimizations.

    we all know that essentials is, uh, slow. in fact, it's so slow, that 18.4 isn't even the first release to be at least partially based on making it faster.

    what is difficult to overstate is just the sheer extent to which this is not necessary.

    everyone who makes the game knows this.

    unknown.png

    unknown.png

    44thg0.png

    that second meme was a big enough deal that it got me to make another release. after everything i've been through. it was just such a big speedup that keeping it to just the devs actively felt bad.

    so let's do storytime.

     

    Event Optimizing

    this is the real basic stuff. in-game events on the map (trainers, doors, anything that results in a change to the map as a result of some kind of interaction) are easily the biggest sources of lag. you can tell what maps have a large number of events simply based on how slowly the map runs. calcenon Gym is my baseline for how laggy the game is simply because of the sheer event density on that map. so a few months ago, when all this optimization shit started, it began by seeing what events were unnecessary and could simply be condensed to a smaller number without resulting in any changes to the overall gameplay. 

    an excellent example of this is spinel.

    every disappearance in spinel takes up some quantity of events. originally this was done with one event per tile that changed as a result of one teleport.

    take the pokemart. here's how it disappears in 18.4:

    image.png

    the pokemart uses 16 events to disappear.

    here's how it is in e19: 

    image.png

    three! one for the graphic, and two to trigger the change if you touch them. the entire graphic is just moved into the one event.

    some areas will definitely be faster because of this, but the downside of this sort of optimization is that it's limited to the areas that have been checked over- and we really have a lot of places that would need to be checked. 

    which leads me to

     

    Script Optimizing

    we've known that there's bloat in the scripts for a while, but the script-side of things is so obscenely large that it'd take ages to find anything to fix that has any sort of impact on actual gameplay.

    and then: toothpastefairy.

    toothpastefairy is our newest, freshest dev. i've mentioned him before as the person behind the battle factory- y'know, the thing that we literally did not expect to happen. this was before he joined the team, too. the sheer number of bugs on our to-do list was enough for him to be promoted from honorary dev to actual real life dev™️. since then we've been getting shit done left and right. bugs getting squished. memes gettin made.

    then, one day, he comes in with this.

    unknown.png

    i hooked up the profiler for myself, and we just went to town on this shit.

    here's some of what we've got.

     

    Quad-calcing the terrain tag

    the above snippet of code is used to determine whether or not a sprite would reflect off the tile in front of it. in doing so, it grabbed the terrain tag four separate times- which is, itself, a time consuming process. fixing this was as easy as assigning the output to a variable and then using the variable for the comparison.

     

    is this a map?

    the terrain tag checking process itself involves taking the coordinates of a tile on the map and shuffling through every layer until you hit one that correctly has a tag.

    however, it also includes this.

    image.png

    are you on a map?

    of course you are. you're playing the game.

    this was removed.

     

    128*4

    so we know that 128*4 = 512 because we can do math.

    image.png

    the in_range? function calculates it again just in case.

    and it does so four times.

    and is one of the most frequently called functions in the entire scripts.

    why.

    this was changed to 512.

     

    is this a control?

    every frame, the game processes whether or not you have a button pressed down. it does so using a process along the lines of this:

    image.png

    here's the thing. there aren't 256 keys on the keyboard. we barely even have half of that. 

    this was carved into three separate sections that go through the keys that actually exist.

     

    the one line change

    this is the big one.

    *breathes

    okay.

    image.png

    so let's talk about what this does.

    essentials uses a function to determine whether or not a sprite should have a reflection.

    this conditional is what essentials uses to add sprites to the list of sprites that should be reflected.

    under normal circumstances, this is determined by whether the event itself specifically says it is not to be reflected. essentials will assume that all sprites should be reflected unless they are explicitly told not to.

    the issue here is that we literally have thousands of events. no one is ever going to put /noreflect/ on every single one of them

    so instead, the new code checks one thing and one thing only: whether the player is currently in serra's gym (map 506).

    do you know what's easier than quad-calcing the terrain tag?

    literally never calling that function at all.

    we've been working up a storm over at Not GameFreak HQ™️ with patching things up left and right

    but it is truly difficult to overstate exactly how huge of a change this is.

    every single event in the game used to go through this giant function, and now it doesn't.

    the change was so freakishly huge, it dropped the frame time reported by the profiler by over 60%.

    now granted the profiler isn't exactly the best at calculating the total time spent on individual functions... but look at the sheer size of that drop for such a minor change. it was inspirational- so much so that i put out another update. after everything i've been through. my computer crashed twice. i had to rebuild my mac vm. but we did it. it's here.

    it's worth noting that 18.4 only includes the one line change right now. it's small enough that it doesn't need to be tested in advance. anything else and i'm worried some weird aspect of this engine will just make everything break completely. 

    but you bet your ass this shit'll be in e19.

    Edited by andracass

    • Like 28
    • Haha 1


    User Feedback

    Recommended Comments

    Quote

     here's the thing. there aren't 256 keys on the keyboard. we barely even have half of that. 

    This whole "just iterate 256 times" breaks my poor programmer's heart.

    It's nice to see the team digging through the old essentials core for optimizations, even though it's painful.

    Share this comment


    Link to comment
    Share on other sites

    Does ruby have structures like hashmaps?

    If so iteration with couples [key:values] is way faster... at least in java 🙂

    ...."flies aways cause none asked my opinion i guess" 😄

    Share this comment


    Link to comment
    Share on other sites
    1 minute ago, netbean said:

    Does ruby have structures like hashmaps?

    If so iteration with couples [key:values] is way faster... at least in java 🙂

    ...."flies aways cause none asked my opinion i guess" 😄

    dude I barely know how to code

    Share this comment


    Link to comment
    Share on other sites

    Yooo, this is awesome (lemme just take this and incorporate it). While simultaneously being tilting cause some of this is such basic stuff being done wrong in the first place (what the hell is with quad-calcing terrain tag, that makes me mad). But if anything, I respect your bravery. We all know how you can make one tiny change to something non-battle related and the code goes "no, I shall not run now, at all"

    Share this comment


    Link to comment
    Share on other sites
    2 minutes ago, Sardines said:

    Yooo, this is awesome (lemme just take this and incorporate it). While simultaneously being tilting cause some of this is such basic stuff being done wrong in the first place (what the hell is with quad-calcing terrain tag, that makes me mad). But if anything, I respect your bravery. We all know how you can make one tiny change to something non-battle related and the code goes "no, I shall not run now, at all"

    no seriously take it

    we have a thing for map connections too

    and we're working on speeding up load times for maps

    i wonder if we could do a preloader.......

    Share this comment


    Link to comment
    Share on other sites

    Yay, another post about code and optimization!

    Great (or terrifying?) findings as always! 

     

    When I saw your announcement on Discord, I thought it rather unbelievable that Essentials could be so broken. 

    But now that I'm reading this post, I found more surprising the fact that creating a new version crashed your computer. 

    What really is in the game?

    What eldritch horror have you unleashed on your players? 

     

    Spoiler

    Apart from Terra, I mean

     

    Edited by Mindlack

    Share this comment


    Link to comment
    Share on other sites

    i=1
    while i==1

       wait(10)

    end

     

    EDIT:

    I shortened my code for increased computational efficiency:

     

    while 1 end

    Share this comment


    Link to comment
    Share on other sites
    1 minute ago, Burningocean2012 said:

    Even with the breakdown I only understand like half of all this but it's a great surprise! ❤️

    its ok fam i gotchu

    *ahem

     

    optimization o'clock: abridged version

    SEE THIS SHIT

    IT BAD

     

    thx

    • Like 1

    Share this comment


    Link to comment
    Share on other sites

    I bet you guys could rewrite the entirety of Essentials to be better as it could possibly be or create your own Essentials.

    Share this comment


    Link to comment
    Share on other sites
    1 hour ago, KolinKat said:

    I bet you guys could rewrite the entirety of Essentials to be better as it could possibly be or create your own Essentials.

    the original essentials itself had a shitload of bugs in it

    so like

    we're probably already there

    • Like 1

    Share this comment


    Link to comment
    Share on other sites
    7 hours ago, andracass said:

    the original essentials itself had a shitload of bugs in it

    so like

    we're probably already there

    Rebrand
    Pokémon Essentials: Cass's super duper works much better then your old-fashioned essentials version 100.2.6

    Ive already copyrighted it for you, Your welcome

     

    Share this comment


    Link to comment
    Share on other sites

    Not gonna lie with all this optimizations it's kind of hard to play the normal game.exe as Game-z.exe is just too good to pass up

    Share this comment


    Link to comment
    Share on other sites
    30 minutes ago, Joboshy said:

    Not gonna lie with all this optimizations it's kind of hard to play the normal game.exe as Game-z.exe is just too good to pass up

    so you're not wrong about game-z, but the good news about this is that game.exe should also be a lot faster!

    Share this comment


    Link to comment
    Share on other sites
    9 minutes ago, andracass said:

    so you're not wrong about game-z, but the good news about this is that game.exe should also be a lot faster!

    Oh so game-z was like a little beta of what ep19 would have? also does that mean we won't have game-z in the ep19 update?

    Share this comment


    Link to comment
    Share on other sites
    1 minute ago, Joboshy said:

    Oh so game-z was like a little beta of what ep19 would have? also does that mean we won't have game-z in the ep19 update?

    game-z is an entirely different engine, but they both run off the same set of scripts. both game and game-z are included to make sure that everyone can play the game (some computers can't run game-z) so they'll both still be in e19.

    Share this comment


    Link to comment
    Share on other sites

    You know I really respect the amount of effort you guys put into this game to make it the best it can be. Good job, give yourself a pat on the back.

    Share this comment


    Link to comment
    Share on other sites

    133oUEt.png

    At least it can't get any worse. Much appreciation to Toothpastefairy, it sounds like he's pulling a lot of weight.

    Share this comment


    Link to comment
    Share on other sites


    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Add a comment...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.


  • E19-Main Scoreboard


    Mapping - #################### | 100%

    Eventing - #################### | 100%

    Story ------ #################### | 100%


    Total ------ #################### | 100%


    E19-Post Scoreboard

     

    Cresselia - ###̳̓###########̳̓###### | 100%

    Regis -----#################### | 100%

    Dogs ------- #################### | 100%

    Spirits ----- #########̖̳̇̌########### | 100%

    Birds ------- #################### | 100%

    Genies ----- ##### ##### ##### ##### | 63%

    Mapping - #################### | 100%

    Eventing - #################### | 90%

    Story ------ #################### | 0%

    Musketeers - ################## | 100%

    Mapping - #################### | 100%

    Eventing#################### | 100%

    Story ------ #################### | 100%

    Regigigas - #################### | 100%

    Mapping - #################### | 100%

    Eventing - #################### | 100%

    Story ------ #################### | 100%

    Celebi ------ #################### | 0%

    Mapping - #################### | 0%

    Eventing - #################### | 0%

    Story ------ #################### | 0%

    Meloetta -- #################### | 0%

    Mapping - #################### | 0%

    Eventing - #################### | 0%

    Story ------ #################### | 0%

    Victini ------ #################### | 5%

    Mapping - #################### | 0%

    Eventing - #################### | 15%

    Story ------ #################### | 0%

    Volcanion - #################### | 0%

    Mapping - #################### | 0%

    Eventing - #################### | 0%

    Story ------ #################### | 0%

    Hoopa ----- #################### | 0%

    Mapping - #################### | 0%

    Eventing - #################### | 0%

    Story ------ #################### | 0%

    Zeraora ---- #################### | 100%

    Mapping - #################### | 100%

    Eventing - #################### | 100%

    Story ------ #################### | 100%

    Magearna - #################### | 0%

    Mapping - #################### | 0%

    Eventing - #################### | 0%

    Story ------ #################### | 0%

    Jirachi ------ #################### | 0%

    Mapping - #################### | 0%

    Eventing - #################### | 0%

    Story ------ #################### | 0%

    Tapus ------ #################### | 0%

    Diancie --- #################### | 0%

    Heatran -- #################### | 0%

    Genesect - #################### | 0%

    Lati@s ----- #################### | 0%

    Manaphy- #################### | 0%

    Darkrai --- #################### | 0%

    Marshadow - ################## | 0%

    Shaymin -- #################### | 0%

    Mew? ------ #################### | 1%

    Mapping - #################### | 5%

    Eventing - #################### | 0%

    Story ------ #################### | 0%

    Dialga/Palkia - #################| 0%

    Groudon/Kyogre - ############## | 0%

    Lugia/Ho-oh - ################# | 0%

    Tau Trio --- #################### | 0%

    Xerneas/Yveltal - ############### | 0%

    Lunala/Solgaleo - ############### | 0%

    Deoxys ----- #################### | 0%

    Giratina --- #################### | 0%

    Rayquaza - #################### | 0%

    Zygarde- ##### ##### ##### ##### | 20%

    Mapping - ##### ##### ##### ##### | 60%

    Eventing - #################### | 0%

    Story ------ #################### | 0%

    Necrozma- #################### | 0%

    Mewtwo- #################### | 1%

    Mapping - #################### | 5%

    Eventing - #################### | 0%

    Story ------ #################### | 0%

    Arceus

    M#̵̤̪̰̺́̑̊̿̽ppping - #̧̠̋̈#̳̓#̮̜̘̤͈̑̽̋̕̚#̵̨̤̪̰̺̳́̑̊̿̽#̵́̑#̞̿̏̾͟͢#̱͡##͉͈̆̐̽͜#̲̤̗̃͛̈́͘͜͜͡#̢̝͍͉̍̐̍͊͘͢#̨̖̳̭͔̇̄͒́͋#̡̫̃̿̕͟#X###̞̿̏̾͟͢## | ?@

    tnevE? - #C###̞̿̏̾͟͢##nO#####͉͈̆̐̽͜#͉͈̆̐̽͜##Y#### | H%

    StoR

     

    Legendary Quest Subtotal:

    ##### ##### ##### ##### ##### |17%


    General ----- #################### | 75%

    Boss Rush -- #################### | 90%

    Theme ------- #################### | 86%

    FITE etc. ----- #################### | 80%

    Fwends ------- #################### | 0%

     

    Nightclub Subtotal:

    ##### ##### ##### ##### ##### | 66%


    Animation - ##### ##### ##### ##### | 63

    Bug Score - ##### ##### ##### ##### | 377

    Misc. -------- #################### | 670%


    EPISODE 19 TOTAL:

    ######################̖̳̇̌#####################̖̳̇̌#########################################################| 52%

    current estimated release date: not this year


    hope you kids like puzzles

    (updated 7/5)

  • 16-4.png
    16-5.png
    16-6.png
    16-7.png
    16-8.png
    16-11.png
    16-12.png

×
×
  • Create New...