On Tue, Jul 12, 2022 at 09:12:56PM +0200, Pavel Sanda wrote:
> Hi,
> 
> I need to adhere precise word/character counts in sections of a document.
> For this I need to have instantaneous visual feedback of stats when selecting
> blocks of text.
> 
> The attached patch does this. Is there some objection to push this into 
> master?
> (If no objection raised I'll add string translation layer to the patch.)

Tested and works well.

However, it seems to have a pretty big hit on performance. The way I
checked was starting with select-all on a document, and then doing shift
+ up and seeing how long it took to get to the top. It took 16 seconds
without the patch and 47 seconds with the patch. I don't have a good
argument for a use case for this particular stress test, but it seems to
raise a flag, and the document I used to test is not too long (it
compiles to a 14 page PDF).

That said, I feel like a considerable amount of users would like this
patch. I would not, but I think it's because my eyes are sensitive. You
can ask JMarc about all of the painting-related issues I've bothered him
about that no one else reported. Part of it is that I just like to
bother JMarc, but I also recognize that I don't like things changing on
the screen and I'm not typical in this sense. If you can solve the
performance issues, I think it would be nice to add an option to
show/remove it. I know there is pushback against yet-another-preference,
but this could go in the context menu of the status bar. Already we have
entries there for "Show Zoom Level" and "Show Zoom Slider" (which I also
like to turn off).

As for how to solve the performance issue, is there any smart caching
that can be done? For example, when selection changes, can you use the
old statistics and then just update the statistics based on the
difference? If this were done, the initial "select-all" would still have
a performance hit, but at least when changing the selection it should
not be too bad. Alternatively, can you store the statistics by
paragraph, and then assuming it is cheap to check if a paragraph has
changed since the last calculation, you can just update the statistics
of the changed paragraphs?

If that doesn't work, would this be a good candidate for asynchronous
calculation? e.g., do the work up to 'from' and 'to' synchronously. Then
do the rest asynchronously. After buf.updateStatistics() is done, you
can check whether:

(1) there is still a selection
(2) 'from' is still the same as cur.selectionBegin()
(3) 'to' is still the same as cur.selectionEnd()

If those checks hold, then write the status.

I know I'm asking to do a lot of work, and this is opening up a big can
of worms for other problems. I might be able to help someday with the
asynchronous design if indeed the caching does not work for some reason
and if there is support from others for it. I've been meaning to study
the latest C++ features anyway whenever I can find the time. I guess the
first step would be: if this will go into 2.5.0 (because of the
asynchronous design), what C++ standard will we require for it? To be
clear, I don't know *when* I could work on this, but we could make a
plan for you to use your patch locally in the meantime and whenever I
can (maybe in a year) I will work on the asynchronous part. Or if anyone
else is interested, they would be welcome :)

Scott

Attachment: signature.asc
Description: PGP signature

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to