On 11/1/18 12:09 PM, Guy Rutenberg wrote:
>
>
> On Thu, 1 Nov 2018 at 17:44, Jürgen Spitzmüller <sp...@lyx.org
> <mailto:sp...@lyx.org>> wrote:
>
>     Am Donnerstag, den 01.11.2018, 16:26 +0100 schrieb Kornel Benko:
>     > This would not be better.
>
>     I was not saying it is good. I was just saying it's not a loop.
>
>
> After some profiling the main culprit is the call to
> get_containing_layout, which is apparently some kind of O(n^2). For
> example for de/Tutorial.lyx there are about ~5000 lines, and we indeed
> call during the conversion we call get_containing_layout 5285 times.
> However, it calls find_end_of_layout a whopping 80936 times.

I fought with these kinds of problems a while ago, too. Things like this
can be surprisingly slow.

I think get_containing_layout could be made a lot faster. The reason for
the complexity is that there might be "embedded" layouts (e.g., in a
footnote), so we can't just look for \\begin_layout. But we probably
could just keep going backwards, keeping track of this 'depth' as we go,
until we find the right \\begin_layout. Probably we could also somehow
make it optional how much info get_containing_layout returns. We do not
need the paragraph params here, for example.

A couple other possibilities.

1. Check first if there are any parens in the line. Only if there are
should we then call get_language_for_line.

2. Go at this differently and keep track, throughout the loop, of what
the current language is. We can start with the document language and
whenever we see a \\lang we switch to that language. We reset to the
document language whenever we see \\end_layout. That might be fastest.

Riki


Reply via email to