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

Rewrite ::address (import from dbus_addr) #989

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

elmarco
Copy link
Contributor

@elmarco elmarco commented Sep 15, 2024

Based on the discussion from #982, import dbus_addr as zbus_address and rebase #562 to make use of it.

@zeenix
Copy link
Contributor

zeenix commented Sep 15, 2024

Thanks! I'll have a look soon. In the meantime, could you please rebase this on top of #976? That one is just waiting for a test case to be added.

Copy link
Contributor

@zeenix zeenix left a comment

Choose a reason for hiding this comment

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

You'll need to change some fundamental design here to make it acceptable to me, sorry.

zbus/src/error.rs Outdated Show resolved Hide resolved
zbus_address/README.md Outdated Show resolved Hide resolved
zbus_address/README.md Outdated Show resolved Hide resolved
zbus_address/README.md Outdated Show resolved Hide resolved
zbus_address/src/lib.rs Outdated Show resolved Hide resolved
zbus_address/src/address.rs Outdated Show resolved Hide resolved
zbus_address/src/address.rs Outdated Show resolved Hide resolved
zbus_address/src/address_list.rs Outdated Show resolved Hide resolved
zbus_address/src/address.rs Outdated Show resolved Hide resolved
zbus_address/src/address.rs Outdated Show resolved Hide resolved
@zeenix
Copy link
Contributor

zeenix commented Sep 17, 2024

I mainly see only 2 blockers here now:

  • The split. As discussed before, I'm not at all convinced a split is worth it in practical terms. We should instead make use of cargo features to make zbus modular instead.
  • The naming.

@elmarco
Copy link
Contributor Author

elmarco commented Sep 17, 2024

I mainly see only 2 blockers here now:

* The split. As discussed before, I'm not at all convinced a split is worth it in practical terms. We should instead make use of cargo features to make zbus modular instead.

* The naming.

I disagree with you on those two points, but if it is what it takes to make progress...

@zeenix
Copy link
Contributor

zeenix commented Sep 17, 2024

I disagree with you on those two points

That's well established. :)

but if it is what it takes to make progress...

I'm sorry but yeah. You've to keep in mind that I did try my best to explain my reasoning in detail. I regret that I failed to convince you in the end.

@elmarco elmarco force-pushed the address branch 6 times, most recently from a0f3be2 to 8b9f688 Compare September 18, 2024 09:34
@elmarco elmarco changed the title Introduce zbus_address & use it Rewrite ::address (import from dbus_addr) Sep 18, 2024
@zeenix
Copy link
Contributor

zeenix commented Sep 18, 2024

@elmarco is this ready for review?

@elmarco
Copy link
Contributor Author

elmarco commented Sep 19, 2024

@elmarco is this ready for review?

yes please

zbus/src/address/percent.rs Show resolved Hide resolved

fn validate(&self) -> Result<()> {
self.transport()?;
let mut set = HashSet::new();
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, aren't we always allocating then for validation (which always happens)? 🤔 The address strings are typically not that long and typically (99% at least IMO) only parsed once so if the API is designed to avoid allocations, it should at least reduce allocations compared to the existing API.

This was my thinking when I decided not to cater for avoiding allocations in 4.0 address API in the end: if in the end I still have allocations, what's the point?

Copy link
Contributor Author

@elmarco elmarco Sep 20, 2024

Choose a reason for hiding this comment

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

I wrote this code the way I thought would be more efficient for parsing, but I never actually went the whole route and checked against nostd etc. I think it's in general superior than always using Vec and String all over. But yes, as I told you earlier, there should be an escape solution for assuming an address is already validated, and/or a way to use no_std (hashset could be replaced quite trivially by a vec from alloc, or a fixed array) . Although having this merged in zbus is now harder to work on and guaratee (same as guarateeing the namespace remain clear of other internal dependencies..).

Copy link
Contributor

Choose a reason for hiding this comment

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

I wrote this code the way I thought would be more efficient for parsing, but I never actually went the whole route and checked against nostd etc.

I think you mean noalloc but that's not what we need. It'll be a pretty big challenge to make zbus nostd and especially noalloc. I'm not expecting that at all from this API. I have a vague plan of adding nostd and noalloc features through the use of heapless crate but that would be a pretty big project and not relevant here.

I think it's in general superior than always using Vec and String all over.

In general, yes and that's my point: is the new API really reducing allocations if it always allocate for validation?

But yes, as I told you earlier, there should be an escape solution for assuming an address is already validated,

I disagree. An address should always be validated, unless built through an unsafe API. This goes in line with the new signature API: zvariant::Signature is now always valid. I don't think this is a strong argument.

and/or a way to use no_std (hashset could be replaced quite trivially by a vec from alloc, or a fixed array)

nostd is not the target here. Reduction/avoidance of allocations is, since that's one of the main arguments for the new API here.

Although having this merged in zbus is now harder to work on and guaratee (same as guarateeing the namespace remain clear of other internal dependencies..).

Not sure I understand but let's focus here: Does the new API proposed here, reduces allocations and if so, how much and if it's worth having all the lifetimes and other complicated parts etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I understand but let's focus here: Does the new API proposed here, reduces allocations and if so, how much and if it's worth having all the lifetimes and other complicated parts etc.

Yes if you skip validation (my intention earlier was obviously behind unsafe.) but I don't think that's the main argument for using this code anyway, almost nobody will care about that, especially if it can't be used directly without the rest of zbus. parsing and and storing result is done through &str references whenever possible.

There has been a lot of reasons listed earlier, if you wish me to make the list again, I could Not to mention it was written before zbus ::address rewrite, which is fundamental in its existence, otherwise, I might have just done something else instead...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also hashset usage is really extra, there is nothing that really prevents addresses from having duplicated keys.. It just seems wrong, because the behaviour isn't described. So if we drop that check, we have no hashset, if that's what worries you about this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and the lifetime usage is one of the most trivial Rust could offer, it references the given string lifetime. Can't be much simpler, you can agree.

Copy link
Contributor

@zeenix zeenix Sep 21, 2024

Choose a reason for hiding this comment

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

Yes if you skip validation (my intention earlier was obviously behind unsafe.)

But why would we want to skip validation at all? That makes no sense to me to bring that up as an argument.

but I don't think that's the main argument for using this code anyway

It has been one of your main arguments, sorry. That and support for address list, which we already established is not something anyone really misses. When I told you that AddressList could simply be a Vec<Address>, your only argument against that was that it will force allocation on people. So forcing tiny amount of allocation on use of an extremely niche API, is a big deal but forcing it on everyone is not?

almost nobody will care about that

That's exactly my point.

especially if it can't be used directly without the rest of zbus.

I told you how you can make that happen, without a lot of effort using cargo features. In fact you can make use of the API break right now to make it happen already in 5.0.

There has been a lot of reasons listed earlier, if you wish me to make the list again

This is the only advantage I see in your list that would require an intrusive re-write of the API that you're proposing. All others could be addressed with the current API.

also hashset usage is really extra, there is nothing that really prevents addresses from having duplicated keys.. It just seems wrong, because the behaviour isn't described. So if we drop that check, we have no hashset, if that's what worries you about this code.

It doesn't worry me one bit. It just contradicts your main argument here.


Anyway, if the spec doesn't dictate this, then we shouldn't do this. In case of duplicate keys, let's just take the last value and document this behaviour?

Copy link
Contributor

Choose a reason for hiding this comment

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

Anyway, if the spec doesn't dictate this, then we shouldn't do this. In case of duplicate keys, let's just take the last value and document this behaviour?

If you agree to this, I believe we can merge this once you've addressed this.

The following commits introduce a different implementation.
Convert to legacy Error::Address string error.
Move connection logic to connect.rs. We start moving parsing to the new
::address step by step, here with top-level list. legacy_address is
going to be gradually replaced.
Compared to the existing implementation, this will take the family into
account (except with tokio), as well as multiple host resolution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants