Re: Use window buffer history to infer buffer ownership: how reliable?

Stefan Monnier via Users list for the GNU Emacs text editor <[email protected]> Thu, 14 May 2026 17:04:18 -0400
Newsgroups gmane.emacs.help
Message-ID <[email protected]>
> 2. Scalability: if I want to find all owners of a given buffer, I
>    would need to walk every live window's history lists. Is this
>    likely to be a performance concern in practice, or is the number
>    of windows small enough that it doesn't matter?

Depends on your usage pattern.  If you can have hundreds of windows (I
routinely have a hundred frames, for example), and if those windows can
have large lists of buffer, then I guess it could be a problem.

OTOH, I'd expect that either you have many windows but most of them only
ever display a single buffer, or have a smallish number of windows.

So, in theory it could be a problem, but in practice I'd expect it's not
an issue (tho I guess it depends also how often you need to compute
"the" window of a buffer).

If you're worried, you could use a `window-buffer-change-functions` hook
to maintain a hash table indexed by buffers which lists all the windows
in which that buffer has been displayed.


=== Stefan