I'm a CS student and in order to practice my coding skills I'm trying to implement an e-book reader and I want some advice from more experienced programmers. I'm using C++\QML but I'll try to keep my problem non-specific to any technology.
Once the book opened I keep it in memory. I also generate an array of pages. Initially I keep in memory:
- the current page;
- 3 pages to left;
- 3 pages to right.
The last two options are needed in order to allow fast scrolling. When the user scrolls one page backward\forward my program calculates a few additional pages in that direction.
I also allow the user to change the window size which affects the page size. And here are problems.
Every time user changes the window size it changes the page size => the program have to recalculate the state of the currently displayed page (its size and content) and also nearby pages. It takes some time.
So every time user just playing around with the app window my program has hard time in calculations. Those calclulations take some time and slow down the whole app.
What I did in order to solve it
- I thought about forbidding user to manually change the window size (and give him a few allowed page sizes) but I'm not sure how user-friendly it is :) In this case I could calculate pages of predefined sizes at the begining so it won't slow down the app as much as it is now.
- I thought multi-threading would save me. As a true newbie at first I did everything in one thread. As long as my app started to actually work (slow of course, because my GUI froze sometimes due to calculations), I introduced multi-threading and now my GUI and working thread are separate. It's faster a little bit now but still sometimes I can see how slow it is especially on a small laptop when you scroll pages faster than a turtle.
So, my question is: how appropriate is my approach? Is it sane at all and what are the ways to improve the perfomance?