Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Algorithm is using in Chrome search?

Assume you are using Chrome, when I press Cmd+F or Ctrl + F... I type a char, it searches the whole page and highlight the text for me. It searches instantly. What kind of algorithm is Chrome using? Why it can type and search so fast? any ideas on that? Thank you.

like image 519
Tattat Avatar asked Nov 20 '10 14:11

Tattat


1 Answers

You can find more information regarding the architecture here: http://www.chromium.org/developers/design-documents/find-bar

I will try to explain a more detailed response that will help you navigate through the Chromium source next time you need something more.

When a user initiates a find in Chromium, we basically register a notification to the observer for results. Every find call is asynchronous, and the results of the search is sent as a notification message by the renderer. This is handled in FindBarController::Observe

The first thing that happens when you press the next/previous/enter, FindBarView::ButtonPressed it tells the current Tab Contents to start finding TabContents::StartFinding. You will notice that in that piece of code it sends an asynchronous request to the IPC. You can view how we send it here: RendererViewHost::StartFinding

Since Chromium is a multi-process architecture, we send messages through the IPC message handler. You can view the link above to see how messages are being sent. The render hosts sends a message to the render view, RenderView::OnFind. From that point on, you know that the find logic is clearly in WebKit source code, not in Chromium. WebFrameImpl::find

Now in WebKit land, the logic where it finds the string is in Editor::findString and if you notice what the algorithm is, basically traversing DOM through a given range using WebKit/WebCore/editing/TextIterator.h The comments in WebKit are not that great in comparison to Chromium, but the quality of the Code is pretty high so you will have no problem reading 3000+ loc.

The reason why I am telling you all this is for your benefit, so if you want to know more about Chromium/WebKit, you know how to look through the source code :) I highly recommend http://dev.chromium.org/developers

like image 193
Mohamed Mansour Avatar answered Sep 30 '22 02:09

Mohamed Mansour