> > And the timings are in the table below? > > | | | no reuse (now) | reuse | > | 1 | Fontify xdisp.c all at once | 0.01s | 0.01s | > | 2 | Fontify 60 next lines of xdisp.c ×10 | 0.10s | 0.00s | > | 3 | Fontify 60 next lines till the end | 6.06s | 0.01s | > > If so, what is the significance of the last line in practical use > cases? JIT font-lock never fontifies such large chunks of source > code, it does that in 512-character chunks, which is less than 60 > lines in most cases, and definitely not "till the end". I think that’s just a way to run font-lock enough times without repeatedly fontifying the same region? > > Also, how much time does it take to do the same with the current > regexp- and syntax-based font-lock, for the same chunks of text? > > We need to examine the use cases and the absolute numbers carefully > before we conclude that any kind of caching is needed and/or > justified. > I redid the benchmark, but without his reuse patch, just to see how much time is spent on creating query objects. So fortifying 40 lines for 463 times takes 6.92s (according to Emacs, 7.30s according to the profiler). That counts to 0.0158s per call to font-lock-region, of which 0.0104s is spent on creating the query object. That seems to tell me if we optimize away the query object creation we can make font-locking very very fast? And not just font-locking, since using tree-sitter to do anything useful basically means querying the parsed tree. If we expose "compiled query” we don’t need to cache them either. The regex-based font-lock is a lot slower. With the optimization or not tree-sitter is a win, but we know that already. I have no idea why regex font-lock ran for 905 loops comparing to 463 for tree-sitter. Maybe I did something wrong there. Benchmark 3: fontify all of xdisp.c, 40 lines at a time. took 6.92, of which 1.00 is GC (0 gc runs), loop count: 463 font-lock: 7.30s -> 0.015766738660907127 / loop ts_query_new: 4.80s -> 0.010367170626349892s / loop Note: 7.30 is taken from external profiler. Benchmark 3: fontify all of xdisp.c, 40 lines at a time. took 88.28, of which 5.00 is GC (4 gc runs), loop count: 905 font-lock: 88.28s -> 0.1997285067873303 / loop Yuan