Skip to content

Conversation

@nevans
Copy link
Collaborator

@nevans nevans commented Oct 24, 2023

  • Similar to ⚡ Simpler, faster response-data parser #201, but for msg-att.
  • Converted the case statement to (mostly) use upcase'd strings, not regexps.
  • The case stmt clauses were sorted. This might help with speed (need better msg-att frequency statistics to back up that claim) but it should definitely help to help avoid conflicts.
    • first the most commonly seen ones (UID and FLAGS),
    • then the ones in both 3051 and 9051 (sorted alphabetically),
    • then the ones in 3051 that were removed from 9051,
    • then MODSEQ (currently, the only supported attribute that's in neither 3501 or 9051).
  • Rewrite the parser for section, section-spec, header-list, header-fld-name.
  • Read the entire msg-att label for BODY[...]<...> prior to the case stmt. This greatly simplifies the code for reading attribute values, allowing much of it to be deleted.

I have written support for several more fetch msg-att, that builds on the changes in this PR:

In my benchmarks, this leads to a measurable performance boost.

To help avoid conflicts later, they were sorted like so: very common
`UID` and `FLAGS`.  Next, in both 3051 and 9051, sorted alphabetically.
Then, in 3051 but not 9051.  Then in 9051 but not 3501.  Then all other
extensions, sorted alphabetically (more or less)
Read entire attr label for `BODY[...]<...>` prior to case stmt.  This
greatly simplifies the code for reading each attribute value, allowing
much of it to be deleted.
@nevans nevans force-pushed the parser/better-faster-cleaner-fetch branch from 2ba8541 to ef38f8e Compare October 26, 2023 02:48
@nevans
Copy link
Collaborator Author

nevans commented Oct 26, 2023

I ran rake benchmarks:compare (see #208) on my phone (no YJIT). At least in this benchmark run and with the fetch examples I ran, they ranged from 1.02x faster to ~1.7x faster. None were slower than the v0.4.2 released version. The results:

$ rake benchmarks:compare BENCHMARK_ARGS="--filter 'fetch|FETCH|body|envelope'"
...
Comparison:
  bodystructure_bug11128_ext_mpart_without_lang
    v0.4.2-23-gef38f8e3:      3872.5 i/s
                  0.4.2:      3781.4 i/s - 1.02x  slower

  bodystructure_bug7146_msg_delivery_status
    v0.4.2-23-gef38f8e3:     18343.7 i/s
                  0.4.2:     16248.6 i/s - 1.13x  slower

  bodystructure_bug7147_message_rfc822_attachment
    v0.4.2-23-gef38f8e3:      6003.1 i/s
                  0.4.2:      5812.1 i/s - 1.03x  slower

  bodystructure_bug8167_delivery_status_with_extra_data
    v0.4.2-23-gef38f8e3:      4405.9 i/s
                  0.4.2:      4043.6 i/s - 1.09x  slower

  bodystructure_extension_fields
    v0.4.2-23-gef38f8e3:      2451.9 i/s
                  0.4.2:         0.0 i/s

  bodystructure_mixed_boundary
    v0.4.2-23-gef38f8e3:      2904.4 i/s
                  0.4.2:      2827.5 i/s - 1.03x  slower

  fetch_msg_att_flags_and_uid
    v0.4.2-23-gef38f8e3:     39067.9 i/s
                  0.4.2:     27161.4 i/s - 1.44x  slower

  fetch_msg_att_modseq
    v0.4.2-23-gef38f8e3:     36117.9 i/s
                  0.4.2:     21175.1 i/s - 1.71x  slower

  fetch_msg_att_rfc822
    v0.4.2-23-gef38f8e3:     54282.0 i/s
                  0.4.2:     38826.3 i/s - 1.40x  slower

  fetch_msg_att_uid
    v0.4.2-23-gef38f8e3:     57431.3 i/s
                  0.4.2:     39290.6 i/s - 1.46x  slower

  invalid_bodystructure_bug7153_mixed
    v0.4.2-23-gef38f8e3:     38287.5 i/s
                  0.4.2:     26330.9 i/s - 1.45x  slower

  invalid_bodystructure_message_sent_as_basic
    v0.4.2-23-gef38f8e3:      3738.5 i/s
                  0.4.2:      3533.7 i/s - 1.06x  slower

  invalid_fetch_msg_att_extra_space
    v0.4.2-23-gef38f8e3:     55393.5 i/s
                  0.4.2:     37536.6 i/s - 1.48x  slower

  invalid_fetch_msg_att_rfc822_with_brackets
    v0.4.2-23-gef38f8e3:     54756.6 i/s
                  0.4.2:     34460.4 i/s - 1.59x  slower

  rfc3501_7.4.2_FETCH_response_example
    v0.4.2-23-gef38f8e3:     43089.8 i/s
                  0.4.2:     28683.5 i/s - 1.50x  slower

  rfc3501_8_example_3_FETCH_ENVELOPE
    v0.4.2-23-gef38f8e3:      4197.2 i/s
                  0.4.2:      3762.7 i/s - 1.12x  slower

  rfc3501_8_example_4_FETCH_BODY[HEADER]
    v0.4.2-23-gef38f8e3:     41381.8 i/s
                  0.4.2:     30450.6 i/s - 1.36x  slower

@nevans nevans merged commit 6dda581 into ruby:master Oct 26, 2023
@nevans nevans deleted the parser/better-faster-cleaner-fetch branch October 26, 2023 03:28
@nevans nevans added the performance related to CPU use, memory use, latency, etc label Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance related to CPU use, memory use, latency, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant