Bug 90596 - Move element/tag category query functions to a separate file
Summary: Move element/tag category query functions to a separate file
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks: 90607
  Show dependency treegraph
 
Reported: 2012-07-05 02:51 PDT by Kwang Yul Seo
Modified: 2012-07-08 22:37 PDT (History)
5 users (show)

See Also:


Attachments
Patch (23.58 KB, patch)
2012-07-05 02:56 PDT, Kwang Yul Seo
no flags Details | Formatted Diff | Diff
Patch (23.60 KB, patch)
2012-07-05 04:21 PDT, Kwang Yul Seo
no flags Details | Formatted Diff | Diff
Patch (26.77 KB, patch)
2012-07-05 05:23 PDT, Kwang Yul Seo
abarth: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kwang Yul Seo 2012-07-05 02:51:57 PDT
Move element/tag category query functions such as isSpecialNode(Node*) to HTMLParserCategory.h/cpp. Currently, these functions are scattered in HTMLTokenizer.cpp and HTMLElementStack.cpp. 

After this patch, we can move HTMLTreeBuilder::furthestBlockForFormattingElement(Element*) method to HTMLElementStack class. This method naturally belongs to HTMLElementStack, but it is currently in HTMLTreeBuilder only because isSpecialNode(Element*) is defined in HTMLTreeBuilder.cpp file.
Comment 1 Kwang Yul Seo 2012-07-05 02:56:29 PDT
Created attachment 150906 [details]
Patch
Comment 2 Early Warning System Bot 2012-07-05 03:00:59 PDT
Comment on attachment 150906 [details]
Patch

Attachment 150906 [details] did not pass qt-ews (qt):
Output: http://queues.webkit.org/results/13141125
Comment 3 Early Warning System Bot 2012-07-05 03:01:26 PDT
Comment on attachment 150906 [details]
Patch

Attachment 150906 [details] did not pass qt-wk2-ews (qt):
Output: http://queues.webkit.org/results/13147031
Comment 4 Build Bot 2012-07-05 03:07:53 PDT
Comment on attachment 150906 [details]
Patch

Attachment 150906 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/13138904
Comment 5 Kwang Yul Seo 2012-07-05 03:13:12 PDT
I will fix build errors soon.
Comment 6 WebKit Review Bot 2012-07-05 03:19:46 PDT
Comment on attachment 150906 [details]
Patch

Attachment 150906 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/13136987
Comment 7 Kwang Yul Seo 2012-07-05 04:21:44 PDT
Created attachment 150923 [details]
Patch
Comment 8 Build Bot 2012-07-05 04:50:27 PDT
Comment on attachment 150923 [details]
Patch

Attachment 150923 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/13143139
Comment 9 Kwang Yul Seo 2012-07-05 05:23:49 PDT
Created attachment 150926 [details]
Patch
Comment 10 Kwang Yul Seo 2012-07-05 05:34:58 PDT
I don't like the name, HTMLParserCategory. Please suggest me a better name for this.
Comment 11 Kwang Yul Seo 2012-07-05 05:36:01 PDT
(In reply to comment #8)
> (From update of attachment 150923 [details])
> Attachment 150923 [details] did not pass mac-ews (mac):
> Output: http://queues.webkit.org/results/13143139

Wow. It is surprisingly hard to make all the build bots green. Modifying Xcode project file by hand is the worst experience!
Comment 12 Adam Barth 2012-07-05 07:06:55 PDT
Comment on attachment 150926 [details]
Patch

I don't see the benefit of this change.  Currently, these functions are defined in the files that use them.  Do we achieve any code sharing with this change?
Comment 13 Kwang Yul Seo 2012-07-05 07:45:33 PDT
(In reply to comment #12)
> (From update of attachment 150926 [details])
> I don't see the benefit of this change.  Currently, these functions are defined in the files that use them.  Do we achieve any code sharing with this change?

I wanted to move HTMLTreeBuilder::furthestBlockForFormattingElement(Element*) to HTMLElementStack. (Bug 90607). There is a FIXME comment:

// FIXME: This probably belongs on HTMLElementStack.
HTMLElementStack::ElementRecord* HTMLTreeBuilder::furthestBlockForFormattingElement(Element* formattingElement)

This method internally uses isSpecialNode(Node*).

After HTMLTreeBuilder::furthestBlockForFormattingElement(Element*) is moved to HTMLElementStack, both HTMLTreeBuilder and HTMLElementStack need to access isSpecialNode(Node*). 

So I moved isSpecialNode(Node*) to a separate file. Because isSpecialNode(Node*) depends on many other functions, I had to move them too.

I named the file HTMLParserCategory.h/cpp since these functions happen to be tag category query functions. Then I moved a few related functions too.

So this patch does not achieve much code sharing. The only code sharing it achieves is isSpecialNode(Node*).

If you think it is better to leave HTMLTreeBuilder::furthestBlockForFormattingElement(Element*) where it is, I'm okay with r-.

Thanks for you review.
Comment 14 Adam Barth 2012-07-08 18:30:29 PDT
I think it's probably not worth fixing.  Perhaps we should remove the FIXME comment?  Generally, FIXME comments are often questions we weren't sure about when we wrote the code originally.  We don't necessarily want to fix all of them.  They're mostly there to help folks working on this code in the future understand what we were thinking originally.
Comment 15 Kwang Yul Seo 2012-07-08 18:33:08 PDT
(In reply to comment #14)
> I think it's probably not worth fixing.  Perhaps we should remove the FIXME comment?  Generally, FIXME comments are often questions we weren't sure about when we wrote the code originally.  We don't necessarily want to fix all of them.  They're mostly there to help folks working on this code in the future understand what we were thinking originally.

Okay. I will close Bug 90607 as WONTFIX too.
Comment 16 Eric Seidel (no email) 2012-07-08 18:41:57 PDT
I probably wrote the fixme.  I kinda like the change... but I suspect we would want to do these all in a header instead.  But as Adam notes, this is probably not worth teh code churn.
Comment 17 Eric Seidel (no email) 2012-07-08 18:42:37 PDT
I really appreciate you looking through all these parser FIXMEs.  As Adam points out, we wrote a whole bunch of FIXMEs while writing the parser.  Not all of which we really should fix.  It's nice that someone is looking through them!
Comment 18 Kwang Yul Seo 2012-07-08 19:01:48 PDT
(In reply to comment #17)
> I really appreciate you looking through all these parser FIXMEs.  As Adam points out, we wrote a whole bunch of FIXMEs while writing the parser.  Not all of which we really should fix.  It's nice that someone is looking through them!

Thanks. One particular FIXME I really want to remove is in HTMLPreloadScanner::scan()

    // FIXME: We should save and re-use these tokens in HTMLDocumentParser if
    // the pending script doesn't end up calling document.write.
    while (m_tokenizer->nextToken(m_source, m_token)) {
        processToken();
        m_token.clear();
    }   

HTMLPreloadScanner is nice, but it fails to save and reuse the tokens because it just uses an approximation of how the tree builder would update the tokenizer's state.

I want to teach HTMLDocumentParser to parse speculatively (in addition to preloading) while it is waiting for scripts. I will file a bug and share my initial design.

Looking through all these parser FIXMEs is a good way to learn the parser code base. I really appreciate your review. Thanks Adam and Eric.
Comment 19 Adam Barth 2012-07-08 20:43:14 PDT
w.r.t. that FIXME, another path is to move the preload scanner to its own thread.  For either change, we really need benchmarks to tell us whether we're making things faster or slower.  Maybe we can both re-use tokens and move the scanner to its own thread?
Comment 20 Kwang Yul Seo 2012-07-08 22:37:40 PDT
(In reply to comment #19)
> w.r.t. that FIXME, another path is to move the preload scanner to its own thread.  For either change, we really need benchmarks to tell us whether we're making things faster or slower.  Maybe we can both re-use tokens and move the scanner to its own thread?

It was tried before in Bug 63531. The patch was rejected because the performance gain was very small.

After we introduce speculative parsing, then maybe we can both re-use tokens and move HTML parsing (not just preload scanning) off the main thread. Firefox exactly doe this.

https://developer.mozilla.org/en/Gecko/HTML_parser_threading
https://bugzilla.mozilla.org/show_bug.cgi?id=483016

Now the discussion is off the topic. I filed Bug 90751 for further discussion.