wx.YieldIfNeeded slows down when called in long running search in wxStyledTextCtrl doc which is scrolled down

24 Views Asked by At

Environment: wxPython v.4.2.2, Python 3.10

There’s editor-like GUI app: Frame->Panel->MultiSplitterWindow->Panel->STC.

I’m implementing Search function as LongRunning, simplified excerpt:

while self.SearchInTarget(stoken) > 0:
    highlighter.FillRange((self.GetTargetStart(), self.GetTargetEnd()))
    self.SetTargetStart(self.GetTargetEnd())
    self.SetTargetEnd(endpos)
    total_found += 1
    start = time.time()
    wx.YieldIfNeeded()
    end = time.time()
    res += end-start
print('Yield took avg time:', res/total_found)

In case the Doc contains large text data and many found tokens, the search runs much longer, but especially when the Doc is scrolled down even for few hundreds lines (of tens thousands). By the measurement I observed that wx.Yield actually runs much longer. Note, I collect search word characters in Queue, then using Thread to read each and send a message to MainThread by QueueEvent (CallAfter/Later were tried as well) with custom event to launch the search loop.

Could someone describe the reason of the scrolling impact and can I work it around? Thanks.

0

There are 0 best solutions below