Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize parsing #358

Merged
merged 9 commits into from Nov 24, 2019
Merged

Optimize parsing #358

merged 9 commits into from Nov 24, 2019

Commits on Nov 23, 2019

  1. Fix existing benchmarks

    The #[cfg(bench)] attribute does not exist and is always false. Lets
    define a feature "bench" which can be used to enable benchmarks when
    building with nightly.
    michalsrb committed Nov 23, 2019
    Copy the full SHA
    db8784f View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    53ef941 View commit details
    Browse the repository at this point in the history
  3. Accept Borrow<Item> as items

    The parse::parse and format::format functions accepted Iterator of owned
    Items. While it is sometimes convenient to pass in the owned values,
    neither of the functions really need to own them, so references would
    be enough. The Borrow trait allows us to pass in Iterator over values,
    references, boxes, etc.
    
    According to RFC 1105 this is a minor change, because it shouldn't break
    any existing code. And chrono is in pre-1.0 version anyway.
    
    This allows us to remove multiple cloned() calls which speeds up parsing
    and formating:
    
     name                                                 control ns/iter  remove-cloned ns/iter  diff ns/iter   diff %  speedup
     datetime::tests::bench_datetime_from_str             712              582                            -130  -18.26%   x 1.22
     datetime::tests::bench_datetime_parse_from_rfc2822   252              244                              -8   -3.17%   x 1.03
     datetime::tests::bench_datetime_parse_from_rfc3339   242              239                              -3   -1.24%   x 1.01
    michalsrb committed Nov 23, 2019
    Copy the full SHA
    05acc86 View commit details
    Browse the repository at this point in the history
  4. Simplify ITEMS in FromStr implementations

    The Item::Space calls str::trim_left and Item::Numeric also calls
    str::trim_left before doing anything else, so there is no need to
    have Item::Space before Item::Numeric.
    
    Speeds up parsing:
     name                                                 remove-cloned ns/iter  simplify-from-str ns/iter  diff ns/iter   diff %  speedup
     datetime::tests::bench_datetime_from_str             582                    448                                -134  -23.02%   x 1.30
     datetime::tests::bench_datetime_parse_from_rfc2822   244                    242                                  -2   -0.82%   x 1.01
     datetime::tests::bench_datetime_parse_from_rfc3339   239                    234                                  -5   -2.09%   x 1.02
    michalsrb committed Nov 23, 2019
    Copy the full SHA
    f731827 View commit details
    Browse the repository at this point in the history
  5. Reimplement scan::number

    The original would first check that there is right amount of numeric
    characters and then parsed them using the std::str::parse, which
    internally checks the characters again and also checks for -/+ prefix,
    which is not necessary in this case.
    
    Since we are already going over the characters, we may as well do the
    parsing ourselves. The length of the function is roughly the same and
    it is faster:
    
     name                                                 simplify-from-str ns/iter  reimplement-number ns/iter  diff ns/iter   diff %  speedup
     datetime::tests::bench_datetime_from_str             448                        365                                  -83  -18.53%   x 1.23
     datetime::tests::bench_datetime_parse_from_rfc2822   242                        195                                  -47  -19.42%   x 1.24
     datetime::tests::bench_datetime_parse_from_rfc3339   234                        166                                  -68  -29.06%   x 1.41
    michalsrb committed Nov 23, 2019
    Copy the full SHA
    6da5359 View commit details
    Browse the repository at this point in the history
  6. Inline some parse related functions

    Speedups:
     datetime::tests::bench_datetime_from_str             365                         337                       -28   -7.67%   x 1.08
     datetime::tests::bench_datetime_parse_from_rfc2822   195                         181                       -14   -7.18%   x 1.08
     datetime::tests::bench_datetime_parse_from_rfc3339   166                         142                       -24  -14.46%   x 1.17
    michalsrb committed Nov 23, 2019
    Copy the full SHA
    a716b48 View commit details
    Browse the repository at this point in the history
  7. Fix build with rust 1.13.0

    michalsrb committed Nov 23, 2019
    Copy the full SHA
    0b8c248 View commit details
    Browse the repository at this point in the history
  8. Temporarily globally allow deprecated

    The question mark will be fixed in a pending commit
    quodlibetor committed Nov 23, 2019
    Copy the full SHA
    27f5e5e View commit details
    Browse the repository at this point in the history
  9. Handle some semantic merge conflicts

    Something that wasn't part of this PR: the work to support nested
    `Option<[ChronoType]>` was merged without being adjusted for the no-std
    support
    
    And now there are some unused import warnings because they need to get
    configged out.
    quodlibetor committed Nov 23, 2019
    Copy the full SHA
    b717e04 View commit details
    Browse the repository at this point in the history