Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow computation for 1M+ suggestions #23

Open
aartaka opened this issue Jul 4, 2023 · 2 comments
Open

Slow computation for 1M+ suggestions #23

aartaka opened this issue Jul 4, 2023 · 2 comments

Comments

@aartaka
Copy link
Contributor

aartaka commented Jul 4, 2023

I've got this code in my Nyxt config:

(define-class unicode-source (prompter:source)
  ((prompter:name "Unicode character")
   (prompter:filter-preprocessor #'prompter:filter-exact-matches)
   (prompter:constructor (loop for i from 0
                               while (ignore-errors (code-char i))
                               collect (code-char i)))))

(defmethod prompter:object-attributes ((char character) (source unicode-source))
  `(("Character" ,(if (graphic-char-p char)
                      (princ-to-string char)
                      (format nil "~s" char)))
    ("Name" ,(char-name char))
    ("Code" ,(format nil "~D/~:*~X" (char-code char)))))

(define-command-global insert-unicode (&key (character (prompt :prompt "Character to insert"
                                                               :sources 'unicode-source)))
  "Insert the chosen Unicode character."
  (ffi-buffer-paste (string character)))

When running the command, I usualy wait some 3-7 seconds for it to load, and the scrolling/narrowing is terribly laggy. Would be nice to optimize something on the Prompter side to make it work :)

@Ambrevar
Copy link
Member

Ambrevar commented Jul 5, 2023

So there are at least 2 performance issues at play here: initialization and view computation.

For the first one, the bottleneck is ensure-suggestions-list which is called in initialize-instance :after of source:

(setf (slot-value source 'initial-suggestions)
            (ensure-suggestions-list source (initial-suggestions source)))

Multiple strategies:

  • Make suggestion objects lazily.
  • Turn ensure-suggestions-list and make-suggestion into regular functions to avoid the dispatch cost.
  • Remove the if in ensure-suggestions-list by writing code in a way we know which type of object we are dealing with.
  • Add types declarations.
  • Declare-optimize.
  • Stack-allocate?

@aartaka
Copy link
Contributor Author

aartaka commented Jul 5, 2023

Yeah, maybe adding a toplevel (declaim (optimize speed)) won't hurt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants