yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.36k stars 873 forks source link

Algorithmic complexity of dep_auto #2318

Closed knokknok closed 3 months ago

knokknok commented 5 months ago

The code for dep_auto in cache.R is O(n^2).

Wouldn't it be possible to only process the globals of the current chunk (i <- "id of current chunk") instead of looping over all the chunks?.

For a document with many chunks, there is a lot of time spent in dep_auto because of the two nested loops.

Thanks for your thoughts!

yihui commented 5 months ago

O(n^2) does sound bad. Do you want to send a PR to simplify it? Sorry I've been quite busy recently.