Skip to content

Improve Query's top-level documentation#18622

Merged
alice-i-cecile merged 5 commits intobevyengine:mainfrom
BD103:query-docs
Mar 31, 2025
Merged

Improve Query's top-level documentation#18622
alice-i-cecile merged 5 commits intobevyengine:mainfrom
BD103:query-docs

Conversation

@BD103
Copy link
Member

@BD103 BD103 commented Mar 30, 2025

Objective

Solution

  • Edit Query's docs for consistency, clarity, and correctness.
  • Make sure to group get() and get_many() together instead of single() and get_many(), to enforce the distinction from Rename get_many() to many(), making it consistent with single() #18615 (comment).
  • Reformat doc tests so they would be readable if extracted into their own file. (Which mainly involves adding more spacing.)
  • Move link definitions to be nearer where they are used.
  • Fix the tables so they are up-to-date and correctly escape square brackets \[ \].

Testing

I ran cargo doc -p bevy_ecs --no-deps to view the docs and cargo test -p bevy_ecs --doc to test the doc comments.

Reviewing

The diff is difficult to read, so I don't recommend just looking at that. Instead, run cargo doc -p bevy_ecs --no-deps locally and read through the new version. It should theoretically read smoother with less super-technical jargon. :)

Follow-up

I want to go through some of Query's methods, such as single(), get(), and get_many(), but I'll leave that for another PR.

@BD103 BD103 added C-Docs An addition or correction to our documentation A-ECS Entities, components, systems, and events D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 30, 2025
@BD103 BD103 added this to the 0.16 milestone Mar 30, 2025
@BD103 BD103 requested a review from Victoronz March 30, 2025 16:45
@Carter0 Carter0 self-requested a review March 30, 2025 17:57
Copy link
Contributor

@chescock chescock 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!

/// |[`get`]\[[`_mut`][`get_mut`]\]|O(1)|
/// |[`get_many`]|O(k)|
/// |[`get_many_mut`]|O(k<sup>2</sup>)|
/// |Archetype-based filtering ([`With`], [`Without`], [`Or`])|O(a)|
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize you didn't change this, but the O(a) here is a little bit misleading. Archetypal filters are evaluated when new archetypes are created, and during iteration they essentially have no cost.

Copy link
Member Author

Choose a reason for hiding this comment

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

How would you change it to make it clearer? Would it be $O(1)$ with a footnote about this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not really sure how to improve it, and I'm fine leaving this alone if we can't think of anything better!

I think the main purpose of this section is to note that Added or Changed evaluate entities one-by-one at query time, while archetype filters don't. In some sense, the problem is that iter() isn't O(n) in the number of matching entities, it's O(n) in the number of entities in matched archetypes, even if those entities get filtered out by non-archetypal filters like Added or Changed.

But I don't know how to say that concisely, so I'm not sure what to suggest writing here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to leave this to a follow-up issue / PR, since I'm not sure either. (My knowledge of the ECS is limited to the user-facing side, I don't know much about the internals!)

Copy link
Contributor

@Carter0 Carter0 left a comment

Choose a reason for hiding this comment

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

Minor thoughts and some questions, but it looks good!

@JaySpruce JaySpruce added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 30, 2025
@BD103 BD103 added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Mar 31, 2025
BD103 and others added 4 commits March 31, 2025 10:36
Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com>
I didn't realize `Single` was defined in the same file! :)
@BD103 BD103 added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Mar 31, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 31, 2025
Merged via the queue into bevyengine:main with commit bb87bd4 Mar 31, 2025
34 checks passed
mockersf pushed a commit that referenced this pull request Mar 31, 2025
# Objective

- There's been several changes to `Query` for this release cycle, and
`Query`'s top-level documentation has gotten slightly out-of-date.
- Alternative to #18615.

## Solution

- Edit `Query`'s docs for consistency, clarity, and correctness.
- Make sure to group `get()` and `get_many()` together instead of
`single()` and `get_many()`, to enforce the distinction from
#18615 (comment).
- Reformat doc tests so they would be readable if extracted into their
own file. (Which mainly involves adding more spacing.)
- Move link definitions to be nearer where they are used.
- Fix the tables so they are up-to-date and correctly escape square
brackets `\[ \]`.

## Testing

I ran `cargo doc -p bevy_ecs --no-deps` to view the docs and `cargo test
-p bevy_ecs --doc` to test the doc comments.

## Reviewing

The diff is difficult to read, so I don't recommend _just_ looking at
that. Instead, run `cargo doc -p bevy_ecs --no-deps` locally and read
through the new version. It should theoretically read smoother with less
super-technical jargon. :)

## Follow-up

I want to go through some of `Query`'s methods, such as `single()`,
`get()`, and `get_many()`, but I'll leave that for another PR.

---------

Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com>
@BD103 BD103 deleted the query-docs branch March 31, 2025 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Docs An addition or correction to our documentation D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants