On 09/01/2018 12:58 PM, Richard Kimberly Heck wrote:
> On 09/01/2018 10:02 AM, Jürgen Spitzmüller wrote:
>> Am Samstag, den 01.09.2018, 13:49 +0200 schrieb Enrico Forestieri:
>>> Using the --verbose switch it can be seen that each time a new
>>> paragraph
>>> is started LyX runs kpsewhich for each bibtex catalog to be found in
>>> the
>>> texmf tree. So, if you have 5 catalogs, kpsewhich is run for 5 times
>>> everytime you hit the Enter key.
>> Indeed, that's likely the culprit.
>>
>> The call is in InsetBibtex::getBibTeXPath(), which is called by
>> InsetBibtex::getBibFiles(), which is called by
>> InsetBibTeX::updateBuffer(), which is called by Buffer::updateBuffer()
>>
>> Would it make sense to cache those paths, too? After all, they are
>> unlikely to change that often.
> Weird that no-one saw this problem on Linux.

Here's a simple patch which would need a bit of additional work, but can
be a kind
of proof of concept (and be tested). Comments?

The only danger of using this as is in 2.3.1 is that, if paths changed,
we would never
know. But that is unlikely to happen.

Riki

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 8ca74103a2..58dd878b5e 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -142,6 +142,7 @@ typedef map<docstring, pair<InsetLabel const *, 
Buffer::References> > RefCache;
 
 // A storehouse for the cloned buffers.
 list<CloneList *> cloned_buffers;
+FileNamePairList Buffer::bibfileCache;
 
 
 class Buffer::Impl
diff --git a/src/Buffer.h b/src/Buffer.h
index 50d086f287..9d34f9c1c3 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -766,6 +766,8 @@ public:
        void updateChangesPresent() const;
        ///
        void registerBibfiles(support::FileNamePairList const & bf) const;
+       ///
+       static support::FileNamePairList bibfileCache;
 
 private:
        friend class MarkAsExporting;
diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index d2e7284052..4b6760c62b 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -397,7 +397,20 @@ FileNamePairList InsetBibtex::getBibFiles() const
        vector<docstring>::const_iterator it = bibfilelist.begin();
        vector<docstring>::const_iterator en = bibfilelist.end();
        for (; it != en; ++it) {
-               FileName const file = getBibTeXPath(*it, buffer());
+               FileNamePairList & cache = buffer().bibfileCache;
+               FileName file;
+               bool found = false;
+               for (auto const & p : cache) {
+                       if (p.first == *it) {
+                               file = p.second;
+                               found = true;
+                               break;
+                       }
+               }
+               if (!found) {
+                       file = getBibTeXPath(*it, buffer());
+                       cache.push_back(make_pair(*it, file));
+               }
 
                if (!file.empty())
                        vec.push_back(make_pair(*it, file));

Reply via email to