@tyrnannoght : the small things in life , precompiled regex in javascript ?

in #tyrnannoght5 years ago

So there is sit, coding the night away with a headache from here to Proxima Centauri, but my head is calm, i mean no mindstorm ... it really helps ...

To think a few months ago i never heard of a-synchronous calls, phaser, babylonJS(which i still havent even tried out for one single line) and now i'm pondering like half hours over stuff like

When it comes to speeding up your web applications, the little things can make quite a difference. One of the ways you can improve the performance of your application is by “precompiling” any regular expressions you use. But wait, JavaScript is an interpreted language. How can a regular expression be precompiled? Well, take a look at the following code:

It's not like i never, i mean i wrote my first commodore basic hello world when i was nine, i'm no stranger from von neumann logic, which is maybe why i think syntax is a waste of brainspace , i mean ... in case of a zombiecalypse it won't really matter if you have google or not to write your programs, right ?

So i got a few scenes working together like the 'main', the UI that's always on and gets refreshed on every call so the statbars reflect nicely what the server says, the inventory screen, the playercharacter-equipped scene, all nice on top of eachother with UI buttons everywhere ... objects are b b*tch imo but its just a way of looking at things i guess.
So every button has a property .val , which i now changed to .type as i'm at the point where i need to start to be able to click items in inventory for use and/or equipping

so i have the regex like
(you know : this.thing.on('pointerdown -> function and what not
pass this.val
this.type in this.case (heh)
then switch on the type property which used to be val
and then

  • case String(this.val.match(/bp[0-9]))

for the backpackslots or

  • case String(this.val.match(/slot[0-50][0-9]))

for the invslots (a max of 50 atm) BUT then i get to thinking, as phaser seems to be quite cpu intensive (probably since GPU in browsers isnt all that for 2D apps ? not sure)
do i regex the numbers out and pass "slot50" as .type like let number = this.type.replace(/ù \D+/g,'')
as intval only takes the lefhand and if the first char encountered is not a number returns null (or nan ?)
or do i add another property .val on button 'creation' ?

in the age of 'add-another-terabyte' most employer scum would probably flay me for that but it doesnt feel right if i dont ... so the article says pre-compiled regex = faster but i think in my case, since its only called on a click and not a loop of 1000 or 10k re-occurrences it might be a matter of a picosecond ( <- weirdo, right)
or less BUT STILL !
i think i might go for the extra property BUT that means the pageload increases in bytevolume, you see ?

what did you say ? just add another terabyte and push it out FAST AND LOTS ? that's a salesforce-thing, you're on the wrong floor, sir, they sit above "us" ... acting like they ARE
(hee hee)

i wonder what will happen if this needs a daily post for the confirmation codes ... it's a utility account which probably means "not good content" by the elder rules (but its STEEMCHAIN PEOPLE , its not reddit or medium, you're like taking a high-powered laser-rifle-battleship to a fistfight with your "good-content" views ...