unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: master 4b5d04b: Use new macro debounce-reduce to make mouse scaling of images more responsive
       [not found] ` <20191123222259.56FE420BE9@vcs0.savannah.gnu.org>
@ 2019-11-24  0:40   ` Stefan Monnier
  2019-11-26 22:10     ` Juri Linkov
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2019-11-24  0:40 UTC (permalink / raw)
  To: emacs-devel; +Cc: Juri Linkov

>     * lisp/emacs-lisp/timer.el (debounce, debounce-reduce): New macros.

Please use proper prefixes for those names.


        Stefan




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: master 4b5d04b: Use new macro debounce-reduce to make mouse scaling of images more responsive
  2019-11-24  0:40   ` master 4b5d04b: Use new macro debounce-reduce to make mouse scaling of images more responsive Stefan Monnier
@ 2019-11-26 22:10     ` Juri Linkov
  2019-11-27  3:32       ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Juri Linkov @ 2019-11-26 22:10 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

>>     * lisp/emacs-lisp/timer.el (debounce, debounce-reduce): New macros.
>
> Please use proper prefixes for those names.

Maybe timer-debounce and timer-debounce-reduce.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: master 4b5d04b: Use new macro debounce-reduce to make mouse scaling of images more responsive
  2019-11-26 22:10     ` Juri Linkov
@ 2019-11-27  3:32       ` Stefan Monnier
  2019-11-27 21:54         ` Juri Linkov
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2019-11-27  3:32 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

>>>     * lisp/emacs-lisp/timer.el (debounce, debounce-reduce): New macros.
>> Please use proper prefixes for those names.
> Maybe timer-debounce and timer-debounce-reduce.

I guess so, tho now that I looked at it I have other questions/comments:

- I don't see `debounce` used anywhere.  Do we need it?
- Why is `debounce-reduce` a macro rather than a function?
- What is the advantage of wrapping a `debounce-reduce` around
  `image--change-size` instead of doing something like:

    (defun image-decrease-size (&optional n)
      "Decrease the image size by a factor of N.
    If N is 3, then the image size will be decreased by 30%.  The
    default is 20%."
      (interactive "P")
      ;; Wait for a bit of idle-time before actually performing the change,
      ;; so as to batch together sequences of closely consecutive size changes.
      (run-with-idle-timer 0.3 nil
                           #'image--change-size
                           (if n
                               (- 1 (/ (prefix-numeric-value n) 10.0))
                             0.8)))

-- Stefan




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: master 4b5d04b: Use new macro debounce-reduce to make mouse scaling of images more responsive
  2019-11-27  3:32       ` Stefan Monnier
@ 2019-11-27 21:54         ` Juri Linkov
  2019-11-27 22:55           ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Juri Linkov @ 2019-11-27 21:54 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

>>>>     * lisp/emacs-lisp/timer.el (debounce, debounce-reduce): New macros.
>>> Please use proper prefixes for those names.
>> Maybe timer-debounce and timer-debounce-reduce.
>
> I guess so, tho now that I looked at it I have other questions/comments:
>
> - I don't see `debounce` used anywhere.  Do we need it?

I prepared a patch that uses `debounce`, but then waited until resolving
the question of prefixes.  But now I installed the patch in b31a966e88
and will add the prefixes afterwards.

> - Why is `debounce-reduce` a macro rather than a function?

In its initial versions that used `body` it needed to be a macro,
but now it can be a function indeed.

> - What is the advantage of wrapping a `debounce-reduce` around
>   `image--change-size` instead of doing something like:
>
>     (defun image-decrease-size (&optional n)
>       "Decrease the image size by a factor of N.
>     If N is 3, then the image size will be decreased by 30%.  The
>     default is 20%."
>       (interactive "P")
>       ;; Wait for a bit of idle-time before actually performing the change,
>       ;; so as to batch together sequences of closely consecutive size changes.
>       (run-with-idle-timer 0.3 nil
>                            #'image--change-size
>                            (if n
>                                (- 1 (/ (prefix-numeric-value n) 10.0))
>                              0.8)))

This version doesn't discard a sequence of consecutive calls
where every call is a costly operation.  For example, on slow hardware
every image resize takes about 1 sec.  Thus when mouse-wheel
generates 5 events, this version will wait for the next idle time,
then will resize the image sequentially 5 times during 5 seconds.

Whereas `debounce-reduce` accumulates all mouse wheel events, and then
calls only one resize operation with the collected scaling factor.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: master 4b5d04b: Use new macro debounce-reduce to make mouse scaling of images more responsive
  2019-11-27 21:54         ` Juri Linkov
@ 2019-11-27 22:55           ` Stefan Monnier
  2019-11-27 23:59             ` Juri Linkov
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2019-11-27 22:55 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

>>                            #'image--change-size
>>                            (if n
>>                                (- 1 (/ (prefix-numeric-value n) 10.0))
>>                              0.8)))
> This version doesn't discard a sequence of consecutive calls
> where every call is a costly operation.  For example, on slow hardware
> every image resize takes about 1 sec.

I understand that but I don't see why you connect the two:
AFAICT `image--change-size` is a very lightweight function which just
changes one value in a plist.  The costly operation happens later during
redisplay.  So if those consecutive calls happen without any redisplay
between them, you should pay for the costly operation only once.

> Thus when mouse-wheel generates 5 events, this version will wait for
> the next idle time, then will resize the image sequentially 5 times
> during 5 seconds.

I would expect that after the idle time it will call
`image--change-size` five times and then perform one costly
recomputation with the resulting new size.


        Stefan




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: master 4b5d04b: Use new macro debounce-reduce to make mouse scaling of images more responsive
  2019-11-27 22:55           ` Stefan Monnier
@ 2019-11-27 23:59             ` Juri Linkov
  0 siblings, 0 replies; 6+ messages in thread
From: Juri Linkov @ 2019-11-27 23:59 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

>>>                            #'image--change-size
>>>                            (if n
>>>                                (- 1 (/ (prefix-numeric-value n) 10.0))
>>>                              0.8)))
>> This version doesn't discard a sequence of consecutive calls
>> where every call is a costly operation.  For example, on slow hardware
>> every image resize takes about 1 sec.
>
> I understand that but I don't see why you connect the two:
> AFAICT `image--change-size` is a very lightweight function which just
> changes one value in a plist.  The costly operation happens later during
> redisplay.  So if those consecutive calls happen without any redisplay
> between them, you should pay for the costly operation only once.
>
>> Thus when mouse-wheel generates 5 events, this version will wait for
>> the next idle time, then will resize the image sequentially 5 times
>> during 5 seconds.
>
> I would expect that after the idle time it will call
> `image--change-size` five times and then perform one costly
> recomputation with the resulting new size.

I didn't expect that the display engine is optimized to handle this case.
Eli asked to try to bind redisplay-dont-pause to nil, then I tried, but
redisplay-dont-pause has no effect.

But it seems run-with-idle-timer could help.  Not sure how I could confirm
that no images are created for intermediate scaling factors, but if visually
it feels more responsive, then run-with-idle-timer should be used.



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-11-27 23:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20191123222254.31152.57547@vcs0.savannah.gnu.org>
     [not found] ` <20191123222259.56FE420BE9@vcs0.savannah.gnu.org>
2019-11-24  0:40   ` master 4b5d04b: Use new macro debounce-reduce to make mouse scaling of images more responsive Stefan Monnier
2019-11-26 22:10     ` Juri Linkov
2019-11-27  3:32       ` Stefan Monnier
2019-11-27 21:54         ` Juri Linkov
2019-11-27 22:55           ` Stefan Monnier
2019-11-27 23:59             ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).