manateelazycat / holo-layer

HoloLayer is a multimedia layer plugin designed specifically for Emacs
GNU General Public License v3.0
132 stars 19 forks source link

"require" in "holo-layer-is-normal-window-p" and "holo-layer-monitor-configuration-change" consume too much cpu #51

Closed Qiutum closed 1 month ago

Qiutum commented 2 months ago

The "require" is a heavy job especially for non-existing package, followings are some benchmark when require non-existing package 100 times in different enviroment. You will find that the "require" consume too much time for non-existing package when load-path has many element.

Such problem make holo-layer lags very much if the user don't has package blink-search or sort-tab installed since both command "holo-layer-is-normal-window-p" and "holo-layer-monitor-configuration-change" call "requires" and they are both called in post-command-hook

+begin_src emacs-lisp

(benchmark-run 100 (require 'non-exist-package nil t))

+end_src

+RESULTS:

: (2.9320095829999997 1 0.40929535400000816)

+begin_src emacs-lisp

(benchmark-run 100 (require 'evil nil t))

+end_src

+RESULTS:

: (0.001063338 0 0.0)

+begin_src bash

emacs -Q --batch --eval \ "(progn (require 'dired) (prin1 (benchmark-run 100 (require 'dired nil t))))"

+end_src

+RESULTS:

: (0.001935583 0 0.0)

+begin_src bash

emacs -Q --batch --eval \ "(prin1 (benchmark-run 100 (require 'non-exist-package nil t)))"

+end_src

+RESULTS:

: (0.08311429199999999 1 0.005793993000000001)

+begin_src bash

emacs -Q --batch --eval "$(cat << EOF (let ((default-directory "~/.emacs.d.default/.local/straight/build-30.0.50")) (normal-top-level-add-subdirs-to-load-path) (prin1 (benchmark-run 100 (require 'non-exist-package nil t))) ) EOF )"

+end_src

+RESULTS:

: (113.71601326 100 1.45376804)

+begin_src bash

emacs -Q --batch --eval "$(cat << EOF (let ((default-directory "~/.emacs.d.default/.local/straight/build-30.0.50")) (normal-top-level-add-subdirs-to-load-path) (prin1 (benchmark-run 100 (require 'dired nil t))) ) EOF )"

+end_src

+RESULTS:

: (0.007873583 0 0.0)

manateelazycat commented 2 months ago

PR are welcome!

manateelazycat commented 1 month ago

https://github.com/manateelazycat/holo-layer/commit/ddd37522b35e5fbb6c2a9e121bc3c48eaf148754 has fixed, thanks for rerpot.