Skip to content

Commit cb495cb

Browse files
[overlays] Fix overlay slowness when huge result is displayed
1 parent eb78711 commit cb495cb

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ 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+
(very-long-value (> (length value) 10000))
235236
(o nil))
236237
;; Remove any overlay at the position we're creating a new one, if it
237238
;; exists.
@@ -245,13 +246,17 @@ overlay."
245246
;; If the display spans multiple lines or is very long, display it at
246247
;; the beginning of the next line.
247248
(when (or (string-match "\n." display-string)
249+
;; string-width can be very slow with huge results, so check
250+
;; with a cheaper predicate first.
251+
very-long-value
248252
(> (string-width display-string)
249253
(- (window-width) (current-column))))
250254
(setq display-string (concat " \n" display-string)))
251255
;; Put the cursor property only once we're done manipulating the
252256
;; string, since we want it to be at the first char.
253257
(put-text-property 0 1 'cursor 0 display-string)
254-
(when (> (string-width display-string) (* 3 (window-width)))
258+
(when (or very-long-value
259+
(> (string-width display-string) (* 3 (window-width))))
255260
(setq display-string
256261
(concat (substring display-string 0 (* 3 (window-width)))
257262
(substitute-command-keys
@@ -285,7 +290,7 @@ overlay."
285290
(when (and (<= (window-start win) (point) (window-end win))
286291
;; Right edge is visible. This is a little conservative
287292
;; if the overlay contains line breaks.
288-
(or (< (+ (current-column) (string-width value))
293+
(or (< (+ (current-column) (string-width display-string))
289294
(window-width win))
290295
(not truncate-lines)))
291296
o)))))))

0 commit comments

Comments
 (0)