Giter Club home page Giter Club logo

Comments (7)

casouri avatar casouri commented on September 27, 2024

I duplicated the buffer content a bunch of times and got a 1k line buffer, then tried the code again. It is still pretty fast, took about 0.1 sec. I think we can probably get away with this approach :-) Add an idle-timer, while-no-input and double-buffering, and it should be smooth.

from emacs.

mickeynp avatar mickeynp commented on September 27, 2024

I will investigate if your code is faster than the dynamic module option. I mean, it almost certainly is. However, the example I gave is of course just a simplified version of the actual tree generator which is primarily -- but not only -- designed for echo area navigational aid as you traverse your code. See:

crop

Now this is the hacky version; the original rendered a proper subset of the sparse tree but that of course (with ETS) turned out to have some performance bottlenecks. This simplified version is probably 'good enough' though.

from emacs.

casouri avatar casouri commented on September 27, 2024

Ah, I see, very interesting feature indeed. I'll wait for you result. If it is still not fast enough, you can describe what you do in more detail, and hopefully we can come up with something in C that can boost the performance for this type use use case.

from emacs.

sebastiansturm avatar sebastiansturm commented on September 27, 2024

while I'm excited to see tree-sitter getting integrated into the Emacs core, I'd very much like the default imenu integration to be synchronous (but fast) and not do anything in the background that might lead to ~100ms latency spikes.
I'm currently using a primitive custom imenu definition that uses the tree-sitter dynamic module to gather a simple list of method names; it's not as pretty as the hierarchical structure shown here, so having both to choose from would be the ideal solution IMO, but it's quick (~3 to 5 ms on files in the 1K line ballpark).

Note that I'm not currently trying to extract scopes, and I'm not sure if that can be done within tree-sitter's query mechanism or if one would have to manually traverse the AST starting from matched nodes (assuming that is supported by the API). Would that be a major performance bottleneck?

For completeness, this is the primitive implementation I'm using (hence the sebastian/ prefix, it's part of my private config):

(defmacro sebastian/define-tsc-index-function (fn-name query)
  `(defun ,fn-name ()
     (unless sebastian/tsc--imenu-query
       (setq sebastian/tsc--imenu-query (tsc-make-query tree-sitter-language ,query)))
     (tsc--without-restriction
      (let* ((matches
              (tsc-query-matches
               sebastian/tsc--imenu-query
               (tsc-root-node tree-sitter-tree) #'tsc--buffer-substring-no-properties)))
        (mapcar (lambda (match)
                  (pcase (cdr match)
                    (`[(name . ,name) (pars . ,pars)]
                     (cons
                      (string-replace
                       "( " "("
                       (s-collapse-whitespace
                        (string-join (list (tsc-node-text name) (tsc-node-text pars)))))
                      (tsc-node-start-position name)))))
                matches)))))

;; for C++ buffers:
(sebastian/define-tsc-index-function
 nq-cc-index-function
 [(function_declarator
   [(operator_name) (field_identifier) (scoped_identifier) (identifier)] @name
   (parameter_list) @pars)])

  (setq imenu-create-index-function #'nq-cc-index-function)

from emacs.

casouri avatar casouri commented on September 27, 2024

Yes, if we do provide a default tree-sitter imenu integration, it would be like what you showed here. I don't think imenu support scope anyway.

from emacs.

mickeynp avatar mickeynp commented on September 27, 2024

I mean, imenu was just an example, of course. It should be blazing fast; indeed, it all should, within the limits of what we can do with Emacs and so forth.

from emacs.

sebastiansturm avatar sebastiansturm commented on September 27, 2024

glad to hear that, no reason for me to worry then :)

from emacs.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.