Balance count-up stutters on cheap Androids, what are you using?

zer0cool99

New Member
Messages
67
Reaction score
0
Location
Seattle, WA

Spent most of last night chasing a jank issue on the payout counter. The number rolls up from the old balance to the new one over about 1.2s and on my Pixel it's glass smooth, on a $90 Tecno it looks like it's having a seizure. Every frame the digits jump instead of rolling and it makes the whole thing feel cheap, which is exactly the wrong feeling when someone just won.

Currently doing the dumb thing: setInterval at 16ms, dumping el.textContent = formatted every tick, and running Intl.NumberFormat fresh each time. I know that's bad. Formatting on every tick is probably half the problem on its own.

What I tried so far:

  • pre-built the formatter once outside the loop, small win, still janky
  • switched to rAF, better on mid tier, Tecno still drops frames
  • will-change: transform on the wrapper, did basically nothing
  • moved to a transform/translateY digit strip instead of swapping text, this is the best result so far but it's a mountain of CSS and I hate maintaining it

Is there something obvious I'm missing? Wondering if the real issue is that these devices just throttle rAF hard when the page has any other animation running, because the reels are still settling in the background while the counter starts. Feels like I'm fighting the browser instead of working with it.

Also curious if anyone's actually happy with a library for this or if you all just hand roll it.

mike_t_2019

Member
Messages
60
Reaction score
0
Location
Leeds, UK

the reels settling in the background is absolutely eating your rAF budget, you already know it. on those cheap Mediatek boxes the compositor is barely keeping up as is, so the moment you ask it to also drive a text counter on the main thread it just gives up and starts stuttering. try freezing the reel animations (animation-play-state: paused, or just bail on the loop) before the counter fires. even a 200ms gap between them is night and day.

second thing, stop formatting every frame. humans can't read a number that's changing 60 times a second anyway, so you only need like 10-12 real value updates across that 1.2s for it to read as smooth. interpolate the raw number, but only run Intl.NumberFormat every 4th or 5th frame. that alone got me from "seizure" to "fine" on a Tecno Spark a while back, before I even touched the DOM strategy.

the digit strip transform is the correct answer btw, and yeah it's miserable to maintain, which is why I gave up hand rolling it. number-flow does exactly that under the hood (search "number-flow", the barvian one, there's also hubspot's odometer which is older and heavier). both are fine, number-flow is the leaner of the two and it doesn't choke on low end hardware. for a casino payout counter I wouldn't bother building your own strip again, not worth the CSS archaeology.

unrelated but this is the exact thing that drives me nuts about the regulated Ontario sites. 1.2s counters, four trackers and a "responsible gaming" popup all fighting for the same frame budget on a $90 phone, and then they wonder why the win feels fake. offshore sites just slam the new balance in there instantly, no animation, and honestly? ngl I prefer it. instant ETH in the wallet beats a pretty rollup every single time lol

have you profiled it with the reels actually disabled though? curious if the counter alone is clean on the Tecno or if you're still dropping frames with nothing else running.

tommy2k

New Member
Messages
69
Reaction score
0
Location
Mexico City, MX

freezing the reels first is the move, yeah. did that on a slot build last year, just killed the animation loop entirely before the counter fired, and it was the single biggest win. felt stupid how much it helped.

but nobody's mentioned proportional digits yet. if your font isn't tabular, every time a digit changes width the whole element reflows, and you're doing that 60 times a second on a phone that's already gasping. slap font-variant-numeric: tabular-nums on the counter (or fall back to a mono) and a chunk of that jank just evaporates. i chased what i thought was an rAF problem for two days and it turned out to be layout thrash from the number getting wider.

on number-flow though, i'll push back a little. it's nice, but it isn't free, and on the actual $90 tier of device the parse/exec cost shows up. if you've already got the digit strip working i'd honestly just keep it. it's ugly to maintain but it's your ugly and you know where the bodies are buried.

also mike your post cut off at "choke on l" and i need to know how that sentence ends lol

LisaW_

New Member
Messages
53
Reaction score
0
Location
Edinburgh, UK

the tabular-nums thing just blew my mind a little. I've been fighting a "wobble" on our win display for weeks and assumed it was the animation, never once thought the digits themselves were changing width. just threw it on and it's noticeably steadier, didn't even touch the loop. so thank you for that one.

question though, does that hold up if the font doesn't ship a mono variant? our designer picked some wonky display face and I'm not sure it has tabular figures at all. do you fall back to a system mono for the counter or just accept the wobble?

also yeah mike, "choke on l" is killing me. l...? lol

jen_93

Member
Messages
62
Reaction score
0
Location
Cape Town, ZA

Lisa, if the display face doesn't actually ship tabular figures then font-variant-numeric: tabular-nums will just sit there doing nothing, silently. Easy way to check: open the font in something like Wakamaifondue or just look at the OpenType feature list in devtools, and if there's no tnum in there you're stuck. No CSS conjures it out of thin air.

What I've done in that exact spot is split the two. Keep the wonky display face for the label ("YOU WON" or whatever), and swap just the digit run to a system mono stack (ui-monospace, Roboto Mono, then a generic fallback). Match the weight and size by eye and honestly nobody clocks it. Slight cheat but it beats a counter that wobbles every time it crosses a 9.

Small pushback on tommy though: if the font can't do tabular, the mono swap is not optional, it's step one. Cheaper and safer than reaching for a library, especially on the device tier we're all apparently cursed with.

One thing nobody's raised. If the value itself is what's animating, you can hand the interpolation to CSS instead of rAF by registering the value with @property as an <integer> and animating it, then rendering it with counter-reset + counter(). The browser drives the tween, your JS just sets the end value once. Chrome on Android handles it fine since it's all off the JS side. Big caveat: formatting. Counters can't do thousands separators without a custom @counter-style and even then it gets ugly for anything above 4 digits. We only used it on a 3-digit multiplier display, so YMMV.

And yeah mike, "choke on l" is the real cliffhanger of this thread. l...azy layout? lol.

ahmed_khan92

New Member
Messages
63
Reaction score
0
Location
Toronto, ON

tommy's right that number-flow isn't free and I'd second keeping your own strip. I tried it on a bonus counter last year and it was smooth on a Pixel 6 and genuinely worse than my hand rolled version on a Redmi 9A. First paint parse cost is real. Libraries that "solve" jank usually just move it somewhere you're not looking yet.

The thing nobody's raised though: 1.2s is too long for this. I know the slow roll feels good when it's smooth, it's satisfying. But on a device dropping every third frame, 1.2s is just 1.2s of visible failure. Cut it to 600-700ms and you've halved the number of frames that can go wrong, and it still reads as a roll. Product will fight you on it, they always do, but that was a bigger win for me than any of the DOM tricks. Shorter animation + frozen reels + 10 real value updates is basically the whole fix.

jen your post cut off at "The br" so I need to know if that was "browser support" or if you were about to tell us about a Brazilian. This thread is cursed, mike never finished "choke on l" either.

One more thing, test on the actual Tecno if you can. Devtools 6x CPU throttle does not reproduce compositor throttling at all, it just makes everything uniformly slow, which isn't the failure mode you're chasing. You'll chase ghosts for a day before you realise the emulator was lying to you. There's a decent thread on this kind of stuff here

https://websiteforums.info/forums/html-css-and-javascript.5/

You must log in or register to reply here.