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

Big Trait Changes #206

Merged
merged 65 commits into from
Nov 23, 2024
Merged

Big Trait Changes #206

merged 65 commits into from
Nov 23, 2024

Conversation

TTWNO
Copy link
Member

@TTWNO TTWNO commented Jun 28, 2024

Summary

Split BusProperties into the const &'static strs (still called BusProperties), and message conversion: MessageConversion (TODO: name).

All trivial events (where they contain only the field item) now implement From<ObjectRef>.

All events that implement From<ObjectRef> get their MessageConversion implementation for free (blanket impl).

Rename:

  • from_message_parts(ObjectRef, Self::Body), to
  • try_from_message_unchecked(&zbus::Message)

An additional check was added to all implementations of From<&zbus::Message> (the macro) requireing that the body signature match the event's body signature—this supplements the xisitng checks on the interface and member.

Commits

  • Split BusProperties into two traits
  • use new trait in sending event code
  • Feature gate new MessageConversion trait behind 'zbus'
  • Take zbus::Body instead of Self::Body in from_message_unchecked
  • from_message_parts_unchecked -> try_from_message_unchecked
  • Pass &Message to new try_from_message_unchecked
  • Add macro to implement From
  • Fix missing doc link
  • Auto-implement MessageConversion for trivial case.
  • Remove now unused From for EventBodyOwned
  • Use full message to check tests
  • Make sure to check signature validity before calling try_from_message_unchecked

TODO

  • Ensure Event and interface-grouped enums use _unchecked instead of TryFrom<&Message>
  • Add _unchecked variant deserialization for interface-grouped enums, which will not check the validity of the interface before continuing,

Copy link

codecov bot commented Jun 28, 2024

Codecov Report

Attention: Patch coverage is 92.55151% with 47 lines in your changes missing coverage. Please review.

Project coverage is 83.87%. Comparing base (5548338) to head (f232b38).
Report is 68 commits behind head on main.

Files with missing lines Patch % Lines
atspi-common/src/events/mod.rs 83.92% 27 Missing ⚠️
atspi-common/src/events/cache.rs 83.16% 17 Missing ⚠️
atspi-common/src/error.rs 0.00% 2 Missing ⚠️
atspi-connection/src/lib.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #206      +/-   ##
==========================================
- Coverage   87.23%   83.87%   -3.36%     
==========================================
  Files          42       43       +1     
  Lines        3595     3231     -364     
==========================================
- Hits         3136     2710     -426     
- Misses        459      521      +62     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@TTWNO
Copy link
Member Author

TTWNO commented Jun 28, 2024

Shout out to our extensive tests that caught a ton of the mistakes I was making along the way! I would have forgot to add the signature check if we didn't have a test specifically that matched the interface+member but gave a blank body.

@TTWNO TTWNO requested a review from luukvanderduim July 1, 2024 02:58
Copy link
Collaborator

@luukvanderduim luukvanderduim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to know whether the 'unchecked' should be marked unsafe as well and whether we should call it unverified, unmatched because the Result seems to suggest things are checked - which they are but not all - which may be clear to us now, but future me may not have a recollection of this.

atspi-common/src/events/keyboard.rs Outdated Show resolved Hide resolved
atspi-common/src/events/mod.rs Outdated Show resolved Hide resolved
@TTWNO TTWNO force-pushed the checked-and-unchecked-tryfrom-msg branch from c8414f0 to 1443168 Compare July 3, 2024 18:08
@TTWNO
Copy link
Member Author

TTWNO commented Jul 3, 2024

Rebased on main.

Copy link
Collaborator

@luukvanderduim luukvanderduim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice improvement over what we have.

I would like to slap a comment or warning on the unchecked and propose to rename it to something descriptive from_identified_message and add its checking sibling to the trait [try_]from_message which will do the tests. See the code review for more thoughts. I am curious to know if you think that makes sense!

atspi-common/src/events/keyboard.rs Outdated Show resolved Hide resolved
atspi-common/src/macros.rs Show resolved Hide resolved
atspi-common/src/events/mod.rs Show resolved Hide resolved
Copy link
Collaborator

@luukvanderduim luukvanderduim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general.
Do we know if there are tangible performance fruits attributable from this PR?
Not sure if the path from Message to Event had become any cheaper but it also should not not be more expensive.

The thing I feel most uncomfortable with is the try_from_validated_message which I think would improve if we renamed it to try_from_message_unchecked. Please see comment in the relevant place.

I'd lile to hear your thoughts.

atspi-common/src/events/mod.rs Outdated Show resolved Hide resolved
@TTWNO
Copy link
Member Author

TTWNO commented Nov 21, 2024

~50% performance increase!

Branch

(I ran this once before capturing the output, so branch is baseline)

Parse 1000 Messages into Events
                        time:   [1.1687 ms 1.1691 ms 1.1694 ms]
                        change: [-1.3389% -1.0516% -0.8445%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 16 outliers among 100 measurements (16.00%)
  4 (4.00%) low severe
  8 (8.00%) low mild
  2 (2.00%) high mild
  2 (2.00%) high severe

Parse 100_000 Messages into Events
                        time:   [114.79 ms 114.82 ms 114.86 ms]
                        change: [-1.7746% -1.7420% -1.7100%] (p = 0.00 < 0.05)
                        Performance has improved.

Main

Benchmarking Parse 1000 Messages into Events: Analyzing
Parse 1000 Messages into Events
                        time:   [2.7034 ms 2.7077 ms 2.7122 ms]
                        change: [+131.22% +131.55% +131.92%] (p = 0.00 < 0.05)
                        Performance has regressed.

Benchmarking Parse 100_000 Messages into Events: Analyzing
Parse 100_000 Messages into Events
                        time:   [268.95 ms 269.22 ms 269.50 ms]
                        change: [+134.24% +134.46% +134.73%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 5 outliers among 100 measurements (5.00%)
  5 (5.00%) high mild

@TTWNO
Copy link
Member Author

TTWNO commented Nov 21, 2024

Excuse the issues with main. I kept pushing there by accident... and Github didn't stop me 🤷

@luukvanderduim
Copy link
Collaborator

Excuse the issues with main. I kept pushing there by accident... and Github didn't stop me 🤷

But your local git branch is tracking a remote branch isn't it?

@TTWNO
Copy link
Member Author

TTWNO commented Nov 21, 2024

Couple untested areas I want to hit before merge. ETA one hour.

@TTWNO
Copy link
Member Author

TTWNO commented Nov 21, 2024

Eh, this PR is too big already, let's just call it here.

Plus it undermines the zbus 5.x PR since signatures are completely different.

@TTWNO TTWNO merged commit a92b8f6 into main Nov 23, 2024
14 checks passed
@TTWNO TTWNO deleted the checked-and-unchecked-tryfrom-msg branch November 23, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants