tarkah / tickrs

Realtime ticker data in your terminal 📈
MIT License
1.2k stars 59 forks source link

Optimizations #54

Closed tarkah closed 3 years ago

tarkah commented 3 years ago

@miraclx Ok, check out this branch. CPU usage is WAY down, especially in summary mode with a bunch of tickers showing. I'm averaging ~3-5% CPU usage in summary mode with 10 stocks on 5yr timeframe. Compared to 0.9.1 uses ~60%.

I added layout caching so I don't have to re-render components if their hashed state & layout dimensions haven't changed. I also did some profiling and found the "prices" method I call a lot in the code is VERY expensive. It was being called inside many of the other methods. I made sure to only call this once per render loop, and pass the data in as a parameter where needed so it wasn't redundantly called.

I also made the change we discussed where I'm cancelling async tasks immediately when time frame is changed vs my previous method of sending a drop message to that future. Switching time frames, even in summary mode, is now instantly responsive. No more lag here.

miraclx commented 3 years ago

Wow. This is a lot. Responsiveness and general performance are through the roof.

👏🏽 Nice work! 🚀

EDIT: Metrics (built in release mode)

tarkah commented 3 years ago

@miraclx Thanks! I should have dug into this a long time ago. I'll get a new release out shortly, just updating some deps since I haven't done that in forever.

miraclx commented 3 years ago

Great. Can't wait.

tarkah commented 3 years ago

EDIT: Metrics (built in release mode)

* On launch, I got a high of 10% CPU utilization

* On switching time frames - max of 3%

* Standby: < 1%

That's so awesome. This will be a huge win for those running on a raspberry pi or the like, as I'm sure before the high CPU usage was felt even worse there.

miraclx commented 3 years ago

Oh yeah!!. I can imagine if it puts that much of a strain on speedy and powerful CPUs, it would've drained the fun out of using the app on those devices.

I'm generally excited for this update. I hope others notice the difference too.

Again, thanks for your work.