Skip to content

Commit 7e9e70c

Browse files
alexander-yakushevbbatsov
authored andcommitted
[overlays] Fix overlay slowness when huge result is displayed
1 parent e905618 commit 7e9e70c

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
### Bugs fixed
1717

1818
- [#3763](https://github.com/clojure-emacs/cider/issues/3763): Fix `cider-docview-render` completion popup error when symbol being completed does not have a docstring.
19+
- [#3774](https://github.com/clojure-emacs/cider/issues/3774): Fix overlay hangup when evaluating huge values.
1920

2021
## 1.16.1 (2024-12-03)
2122

cider-overlays.el

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ overlay."
232232
;; Specify `default' face, otherwise unformatted text will
233233
;; inherit the face of the following text.
234234
(display-string (format (propertize format 'face 'default) value))
235+
;; Maximum value width at which we truncate it.
236+
(truncation-threshold (* 3 (window-width)))
235237
(o nil))
236238
;; Remove any overlay at the position we're creating a new one, if it
237239
;; exists.
@@ -245,17 +247,22 @@ overlay."
245247
;; If the display spans multiple lines or is very long, display it at
246248
;; the beginning of the next line.
247249
(when (or (string-match "\n." display-string)
250+
;; string-width can be very slow on large results, so check
251+
;; with a cheaper predicate first. Conservatively limit to
252+
;; truncation threshold.
253+
(> (length display-string) truncation-threshold)
248254
(> (string-width display-string)
249255
(- (window-width) (current-column))))
250256
(setq display-string (concat " \n" display-string)))
251-
;; Put the cursor property only once we're done manipulating the
252-
;; string, since we want it to be at the first char.
253-
(put-text-property 0 1 'cursor 0 display-string)
254-
(when (> (string-width display-string) (* 3 (window-width)))
257+
(when (or (> (length display-string) truncation-threshold)
258+
(> (string-width display-string) truncation-threshold))
255259
(setq display-string
256-
(concat (substring display-string 0 (* 3 (window-width)))
260+
(concat (substring display-string 0 truncation-threshold)
257261
(substitute-command-keys
258262
"...\nResult truncated. Type `\\[cider-inspect-last-result]' to inspect it."))))
263+
;; Put the cursor property only once we're done manipulating the
264+
;; string, since we want it to be at the first char.
265+
(put-text-property 0 1 'cursor 0 display-string)
259266
;; Create the result overlay.
260267
(setq o (apply #'cider--make-overlay
261268
beg end type
@@ -285,7 +292,7 @@ overlay."
285292
(when (and (<= (window-start win) (point) (window-end win))
286293
;; Right edge is visible. This is a little conservative
287294
;; if the overlay contains line breaks.
288-
(or (< (+ (current-column) (string-width value))
295+
(or (< (+ (current-column) (string-width display-string))
289296
(window-width win))
290297
(not truncate-lines)))
291298
o)))))))

0 commit comments

Comments
 (0)