Skip to content

Leak in overlays when hideshowvis-ignore-same-line is t #11

@eyal0

Description

@eyal0

Bug

In this code:

hideshowvis/hideshowvis.el

Lines 143 to 158 in e48500e

(let* ((ovl (make-overlay (match-beginning 0) (match-end 0)))
(marker-string "*hideshowvis*")
(doit
(if hideshowvis-ignore-same-line
(let (begin-line)
(setq begin-line
(save-excursion
(goto-char (match-beginning 0))
(line-number-at-pos (point))))
(save-excursion
(goto-char (match-beginning 0))
(ignore-errors
(progn
(funcall hs-forward-sexp-func 1)
(> (line-number-at-pos (point)) begin-line)))))
t)))

We see that an overlay is created on line 143. On lines 146-158, if hideshowvis-ignore-same-line is t then we might not actually use the overlay just created, by setting doit to false.

When we don't use the overlay, we also don't later on set the property hideshowvis-hs on the overlay, which is done on line 168 within the when doit block.

This causes the code to sometimes create overlays without putting the hideshowvis-hs property on them.


When recomputing the overlays, the first step is to remove all the old overlays, on this line:

(remove-overlays (point-min) (point-max) 'hideshowvis-hs t)

However, it only removes the overlays with the hideshowvis-hs property. The overlays for which doit was not true will never get deleted, and this causes the number of overlays to balloon, leading to major slowdowns in the buffer.

Testing

  1. Open a buffer with hideshowvis enabled and type M-: (length (overlay-lists)). You will see how many overlays there are.
  2. M-x revert-buffer to reload the buffer. This will recompute the hideshowvis.
  3. Again M-: (length (overlay-lists)). You will see that there are many more overlays now.

If you do this test with hideshowvis-ignore-same-line set to t then it will not balloon the number of overlays because they will all get marked with the hideshowvis-hs property.

Solution

Very simple: In the case of doit false, don't make an overlay in the first place!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions