Bug 261123

Summary: Performance improvement for the word boundary finding algorithm (findNextWordFromIndex)
Product: WebKit Reporter: Ahmad Saleem <ahmad.saleem792>
Component: HTML EditingAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: karlcow, mmaxfield, rniwa, simon.fraser, webkit-bug-importer, wenson_hsieh, zalan
Priority: P2 Keywords: InRadar, Performance
Version: Safari 16   
Hardware: Unspecified   
OS: Unspecified   
URL: https://jsfiddle.net/1ucrpsq5/show
See Also: https://bugs.webkit.org/show_bug.cgi?id=114088

Description Ahmad Saleem 2023-09-04 14:23:29 PDT
Hi Team,

While going through Blink's commit, I came across test case, where Safari hangs (it is performance test case, so it is kind of edge case).

Both Chrome Canary 118 and Firefox Nightly 118 are fast and complete it in 3xx milliseconds while I am unable to see timing for Safari due to hangs.

Test Case - in URL field.

Just wanted to raise so we can fix it.

Thanks!
Comment 1 Karl Dubost 2023-09-04 18:17:38 PDT
This is indeed failing quite hard.
Comment 2 Radar WebKit Bug Importer 2023-09-04 18:17:46 PDT
<rdar://problem/114954726>
Comment 3 zalan 2023-09-05 10:18:48 PDT
Looks like we spend some time in nextWordFromIndex:forward

32.79 s   82.2%	0 s	 	                          WebCore::jsDOMSelectionPrototypeFunction_modify(JSC::JSGlobalObject*, JSC::CallFrame*)
32.79 s   82.2%	0 s	 	                           WebCore::DOMSelection::modify(WTF::String const&, WTF::String const&, WTF::String const&)
32.79 s   82.2%	0 s	 	                            WebCore::FrameSelection::modify(WebCore::FrameSelection::EAlteration, WebCore::SelectionDirection, WebCore::TextGranularity, WebCore::EUserTriggered)
32.79 s   82.2%	0 s	 	                             WebCore::FrameSelection::modifyExtendingForward(WebCore::TextGranularity)
32.79 s   82.2%	0 s	 	                              WebCore::FrameSelection::nextWordPositionForPlatform(WebCore::VisiblePosition const&)
32.79 s   82.2%	0 s	 	                               WebCore::nextWordPosition(WebCore::VisiblePosition const&)
32.79 s   82.2%	0 s	 	                                WebCore::nextBoundary(WebCore::VisiblePosition const&, unsigned int (*)(WTF::StringView, unsigned int, WebCore::BoundarySearchContextAvailability, bool&))
32.79 s   82.2%	0 s	 	                                 WebCore::forwardSearchForBoundaryWithTextIterator(WebCore::TextIterator&, WTF::Vector<char16_t, 1024ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc>&, unsigned int, unsigned int (*)(WTF::StringView, unsigned int, WebCore::BoundarySearchContextAvailability, bool&))
29.34 s   73.6%	0 s	 	                                  WebCore::findNextWordFromIndex(WTF::StringView, int, bool)
27.03 s   67.8%	0 s	 	                                   -[NSAttributedString(NSAttributedStringUIFoundationAdditions) nextWordFromIndex:forward:]

(changing component to editing)