Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

handle_in_body: Replaced if/else-if with switch/case stmt #370

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sebcat
Copy link

@sebcat sebcat commented Sep 29, 2016

gprof on benchmark before change:
Flat profile:

Each sample counts as 0.01 seconds.
%   cumulative   self              self     total
time   seconds   seconds    calls  ms/call  ms/call  name
12.15      0.57     0.57 38932310     0.00     0.00  handle_in_body
 8.10      0.95     0.38 45036450     0.00     0.00  gumbo_lex
 6.82      1.27     0.32                             gumbo_parse_with_options
 6.61      1.58     0.31 98682890     0.00     0.00  read_char
 5.33      1.83     0.25 92378210     0.00     0.00  gumbo_string_buffer_append_codepoint
 5.33      2.08     0.25 45037230     0.00     0.00  abandon_current_tag
 3.20      2.23     0.15 92378210     0.00     0.00  maybe_resize_string_buffer
 2.99      2.37     0.14 98676780     0.00     0.00  utf8_is_invalid_code_point
 2.77      2.50     0.13 37336260     0.00     0.00  reconstruct_active_formatting_elements
 2.56      2.62     0.12 59399950     0.00     0.00  maybe_emit_from_temporary_buffer

gprof on benchmark after change:
Flat profile:

Each sample counts as 0.01 seconds.
%   cumulative   self              self     total
time   seconds   seconds    calls  ms/call  ms/call  name
8.41      0.35     0.35                             gumbo_parse_with_options
7.21      0.65     0.30 45036450     0.00     0.00  gumbo_lex
6.73      0.93     0.28 98682890     0.00     0.00  read_char
4.57      1.12     0.19 98676780     0.00     0.00  utf8_is_invalid_code_point
4.33      1.30     0.18 92378210     0.00     0.00  gumbo_string_buffer_append_codepoint
4.09      1.47     0.17 45037230     0.00     0.00  abandon_current_tag
3.61      1.62     0.15 98670910     0.00     0.00  utf8iterator_next
3.49      1.77     0.15 38932310     0.00     0.00  handle_in_body
3.13      1.90     0.13 42229930     0.00     0.00  emit_char
2.88      2.02     0.12 99583440     0.00     0.00  parser_add_parse_error

CLA signed. Ran clang-format on src/parser.c. Compared prettyprint serializations of benchmarks/*.html, output from prettyprint on master and modified branch were identical (same sha1sum output). Ran make check:

PASS: gumbo_test
============================================================================
Testsuite summary for gumbo 0.10.1
============================================================================
# TOTAL: 1
# PASS:  1
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================

gprof on benchmark before change:
Flat profile:

Each sample counts as 0.01 seconds.
%   cumulative   self              self     total
time   seconds   seconds    calls  ms/call  ms/call  name
12.15      0.57     0.57 38932310     0.00     0.00  handle_in_body
 8.10      0.95     0.38 45036450     0.00     0.00  gumbo_lex
 6.82      1.27     0.32                             gumbo_parse_with_options
 6.61      1.58     0.31 98682890     0.00     0.00  read_char
 5.33      1.83     0.25 92378210     0.00     0.00  gumbo_string_buffer_append_codepoint
 5.33      2.08     0.25 45037230     0.00     0.00  abandon_current_tag
 3.20      2.23     0.15 92378210     0.00     0.00  maybe_resize_string_buffer
 2.99      2.37     0.14 98676780     0.00     0.00  utf8_is_invalid_code_point
 2.77      2.50     0.13 37336260     0.00     0.00  reconstruct_active_formatting_elements
 2.56      2.62     0.12 59399950     0.00     0.00  maybe_emit_from_temporary_buffer

gprof on benchmark after change:
Flat profile:

Each sample counts as 0.01 seconds.
%   cumulative   self              self     total
time   seconds   seconds    calls  ms/call  ms/call  name
8.41      0.35     0.35                             gumbo_parse_with_options
7.21      0.65     0.30 45036450     0.00     0.00  gumbo_lex
6.73      0.93     0.28 98682890     0.00     0.00  read_char
4.57      1.12     0.19 98676780     0.00     0.00  utf8_is_invalid_code_point
4.33      1.30     0.18 92378210     0.00     0.00  gumbo_string_buffer_append_codepoint
4.09      1.47     0.17 45037230     0.00     0.00  abandon_current_tag
3.61      1.62     0.15 98670910     0.00     0.00  utf8iterator_next
3.49      1.77     0.15 38932310     0.00     0.00  handle_in_body
3.13      1.90     0.13 42229930     0.00     0.00  emit_char
2.88      2.02     0.12 99583440     0.00     0.00  parser_add_parse_error
@nostrademons
Copy link
Contributor

Thanks for the patch! Nice speedup.

The Travis CI is failing for what appears to be an unrelated reason - it can't fetch the gtest distribution, which has been moved off of GoogleCode and is now on GitHub. I should fix that in a separate change - it could be replaced by a subinclude now that GTest is on Git - but for now I'll take your word that you ran all the tests and they passed.

@nostrademons
Copy link
Contributor

Oh hmm, apparently I can't merge because I'm no longer a member of the Google organization (I haven't worked there in 2 years now). Any other Googlers still paying attention to this? I'd be quite open to transferring maintainership to someone else as well, since I've rarely had time to give this library the attention it deserves.

kovidgoyal added a commit to kovidgoyal/html5-parser that referenced this pull request Jul 25, 2017
Replace giant if/elif by switch()
See google/gumbo-parser#370
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants