cedar-policy / cedar

Implementation of the Cedar Policy Language
https://www.cedarpolicy.com
Apache License 2.0
889 stars 80 forks source link

improve performance of deserializing invalid json policies #1308

Closed cdisselkoen closed 1 week ago

cdisselkoen commented 1 week ago

Description of changes

Replaces the derived Deserialize implementation for est::Expr with a custom one, resulting in greatly improved performance on the #1284 benchmark (see #1307). Should be a performance improvement for a wide variety of invalid est::Exprs. Hopefully not a slowdown for the happy path, that is, valid est::Exprs.

On my machine, the new numbers for the #1284 benchmark are:

Policy::from_json       time:   [107.54 µs 107.61 µs 107.70 µs]
                        change: [-99.997% -99.997% -99.997%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  1 (1.00%) low mild
  3 (3.00%) high mild
  2 (2.00%) high severe

That is, performance has improved from about 3.4s to execute once, to about 108 µs.

Issue #, if available

Fixes #1284.

Checklist for requesting a review

The change in this PR is (choose one, and delete the other options):

I confirm that this PR (choose one, and delete the other options):

I confirm that cedar-spec (choose one, and delete the other options):

I confirm that docs.cedarpolicy.com (choose one, and delete the other options):