Help with performance tips and practices

Godot V: 4.2.1

Hey, good day everyone! long days and pleasant nights.
I was wondering about a couple of performance related things.

Context:
I am developing a VR book reading application for the quest 2 + 3 (only got a 2, but it should work on the 3) where you can actually pick up the books. So this would include a lot of book models and a library which the player can wander around in.

Bit by bit ill figure it out, but the main problem I do not want to bump into again is performance. Since this is a redo of the project, first time around was in unity, where unity itself decided to crap out on me (issues with exporting the game to the quest). Where I also ran into heavy performance issues. Some notable “fixes” include: not unzipping every .epub file every time you open it, not loading every book right of the bat.

So I wanted to put my current approach on the table and ask some kind strangers for advice on how it could improve and if my methods are sound.

As what I am intending on implementing currently is a system where every book is a frozen grab-able rigid body. frozen to avoid collisions.

Where the nodes under the rigid body are the collision shape and a “Handler”.

When the book is grabbed it calls a function within the handler which switches the low detail model the book is currently using to a high detail model (disable low detail child node, enable high detail child node) and enables text and pictures.

With this it loads in the actual “book” from the VersOne .epub library together with object references which were previously initialized as null global variables.

At the loading of a chapter (like when it opens) it assigns the chapter to the left page (so one whole chapter of a book).
At the second frame it gets the AABB.Size.Y of the text and the amount of characters on the page.
then it divides the number of characters by AABB.Size.Y/28 (28 fits on the book model properly) and cuts off the characters after the found index.
It will repeat this divide and cut until the size is under 28 (to ensure that no \n messes with it).

When going to the next page it will do the same as above but with the cut text, when going back a page it will use the index it saved of where the previous page began within the big piece of chapter text.

Thank you for any advice!
Kind regards,
Lilith

1 Like

Caching is good, you seem to have that down.

Preprocessing is another thing. I don’t understand your explanation for the AABB thing, which is a physics related concept, but it’s just a bounding rectangle. Anyway I feel like that iterative process doesn’t need to happen. You should render the epub as you intend it to be viewed. Or at least limit to one framing step. (I don’t know epub data very well, I’m imagining a kindle where it can size a page based on font size.)

If you can’t optimize that divide thing, another option is, While the first chapter is being read you can begin prepping the next chapter. You could try and do this slow or keep it at the pace of the reader.

Less things for the process or to do, the better.

Take the epub and change to another format?

1 Like

Oh yeah, AABB gets the bounding box size of the text, so if i put in more text than fits on the 3d model of the book the Y value of size will be bigger than 28.
So ill need to cut of the text which does not fit, small issue is, that an \n counts as one character, but from a displayed text perspective takes up an entire line of characters. so i might need to iterate to fix that, ideally it only needs to cut once of-course.

I was thinking it might be beneficial to right of the bet just find a “max-character” number, which finds how many characters are allowed on one page and pre-cuts by that before even setting the text the first time (font can be adjusted in size so i can’t hard-code).
As the worst performance drop I’ve had before was by heavily overfilling a textbox, as it required a lot of memory and surprisingly enough graphics due to it converting text to a mesh.