I have a question about ram usage when using overlays.
So I have created `image-roll.el` for displaying documents/books (see here).
However, I have just noticed that it uses a large amount of RAM when viewing (or
trying to) pages in the back of 'large' books. But even if RAM usage still looks
perfectly fine, Emacs crashes when trying to scroll to higher page numbers.
I have looked a little into it, and have found that it is a consequence of using
large overlays. There is no problem when creating a buffer containing many
overlays, however, when trying to scroll to some overlay at the end of the buffer,
Emacs will use huge amounts of RAM.
So I am wondering if this is 'necessary' behavior; and then why is it necessary?
The issue occurs even when displaying the same 'empty' svg-image on each
overlay, but it occurs also when simply displaying some 'specified space' on
each overlay.
I have created a simple test file (attached to this mail) for reproducing the
issue.From 'emacs -Q` you can simply load the file and do `M-x test`. Then you
can type some number and press `C-c C-c` to jump to the page/overlay(number)
(use arrow up/down to scroll). The overlay width is set to 1200 pixels (via a
global variable, so that it can easily be changed) and the width is set to 1.4
times that size (you can also comment out the 'specified space' overlay, and
uncomment the `insert-image` form). Over here, Emacs crashes when trying to jump
to a page number of somewhere around 1750. When increasing the overlay size,
e.g. setting the width to (window-pixel-width), then RAM usage increases much
faster, and Emacs starts to crash from jumping to page around 800.
So my question is, if it is really necessary that Emacs uses so much RAM for just
displaying 'empty spaces'. And another question is why the maximum `vscroll` is
(or seems to be) limited.
I have designed the book-roll like this, so that the scroll bar might be used
for indicating/scrolling to the/some position in a document. However, otherwise
I probably have to design it so that the buffer only contains two overlays and
'simulate' the image-roll behavior.