Yesterday I worked on fixing issue #722 
<https://github.com/leo-editor/leo-editor/issues/722> (replace-all can not 
be saved with crtl + s), I have found that culprit was inside replace-all 
command caused by avoiding to use p.setDirty() because of its cost, and 
using rather p.v.setDirty().

The difference between the two is that p.setDirty, traverses parents and 
calls setDirty on them also, while p.v.setDirty just sets dirty bit in p.v

At first, it seemed to me that really this propagation of setting dirty bit 
to all parents and grandparents must be too expensive to be used inside 
replace-all loop. That is why I wrote just one loop after replace-all is 
finished to set dirty flags to all nodes that are affected by replace-all 
command.

Today I have looked in p.setDirty and I've found that it is overly 
complicated and as one might expect accordingly expensive. I don't know if 
this method has other duties to perform, but if it is just setting dirty 
bit to all nodes that have in their subtree p.v, then it strikes me as odd 
that this method should be so expensive.

I have made small experiment script that counts how many nodes should be 
affected if any given vnode is setDirty, and shows maximum, and average 
value of this count for all vnodes in my copy of LeoPyRef.leo.

Maximum was 35, and average is 7.1. Now, flipping one bit in 35 nodes can't 
be that expensive. Here is a function that propagates dirty flag to all 
ancestors in the outline of given vnode.
def mkDirty(v):
    v.setDirty()
    for v1 in v.parents:
        mkDirty(v1)

Measuring this function on the node with most ancestor nodes   
UNL:(#Notes-->@file ../doc/leoNotes.txt-->Test code: do not delete-->Unused 
unit tests-->@ignore mini tests-->Other tests-->Printing tests...-->Print 
iterations: do not delete-->b-->c-->c2-->c3), using timeit module gives the 
following results:

calls[n=100000]  avg:0.033ms

What would be the consequences of replacing Position.setDirty method with 
the above function? Does that method have some other responsibilities that 
I am not aware of? Perhaps those responsibilities can be divided in several 
methods and this one responsibility delegated to new method (for example: 
propagateDirty)?

Vitalije

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to