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

refactor(http): Use query string helper #2348

Merged
merged 11 commits into from
May 31, 2024
Merged

Conversation

suneettipirneni
Copy link
Member

@suneettipirneni suneettipirneni commented May 22, 2024

This is created based on the discussion here as well as here.

@suneettipirneni suneettipirneni requested a review from a team May 22, 2024 23:10
@suneettipirneni suneettipirneni self-assigned this May 22, 2024
@github-actions github-actions bot added c-http Affects the http crate t-refactor Refactors APIs or code. labels May 22, 2024
Copy link
Member

@laralove143 laralove143 left a comment

Choose a reason for hiding this comment

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

thank you for the great work!

twilight-http/Cargo.toml Outdated Show resolved Hide resolved
twilight-http/src/query_array.rs Outdated Show resolved Hide resolved
twilight-http/src/query_array.rs Outdated Show resolved Hide resolved
twilight-http/src/query_array.rs Outdated Show resolved Hide resolved
twilight-http/src/query_array.rs Outdated Show resolved Hide resolved
twilight-http/src/routing.rs Outdated Show resolved Hide resolved
Copy link
Member

@vilgotf vilgotf left a comment

Choose a reason for hiding this comment

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

We've been very strict about Display performance so this is an unacceptable regression. Since query_string_builder cannot be made lazy (a requirement for us) I propose vendoring a similar API, without allocations. We can iterate on such an API on Discord

twilight-http/src/routing.rs Outdated Show resolved Hide resolved
@sunsided
Copy link

We've been very strict about Display performance so this is an unacceptable regression. Since query_string_builder cannot be made lazy (a requirement for us) I propose vendoring a similar API, without allocations. We can iterate on such an API on Discord

Author of the library here. I'd love to understand the use case. Is this simply about deferring the call to to_string() until the query string is actually to be rendered?

@laralove143
Copy link
Member

We've been very strict about Display performance so this is an unacceptable regression. Since query_string_builder cannot be made lazy (a requirement for us) I propose vendoring a similar API, without allocations. We can iterate on such an API on Discord

while i agree with the (arguably little) performance penalty of using this method, i think we need to consider the 20/80 rule here

while a simple change from format!() to f.write_str() is worth it for the performance gain, writing our own query string builder might not be worth it

not to mention, i feel that this goes beyond the scope of twilight, if we can find a library that fits our criteria better or if someone volunteers to write such a library, i agree that we should use that library instead

@vilgotf
Copy link
Member

vilgotf commented May 24, 2024

Author of the library here. I'd love to understand the use case. Is this simply about deferring the call to to_string() until the query string is actually to be rendered?

My usage of "lazy" was not quite correct. What I meant is that we want to avoid creating temporary Strings for keys and values. We have a very big performance focus so I'm unsure if whatever API we come up with here should be broadly encouraged.

@sunsided
Copy link

sunsided commented May 24, 2024

Author of the library here. I'd love to understand the use case. Is this simply about deferring the call to to_string() until the query string is actually to be rendered?

My usage of "lazy" was not quite correct. What I meant is that we want to avoid creating temporary Strings for keys and values. We have a very big performance focus so I'm unsure if whatever API we come up with here should be broadly encouraged.

Thanks for clarifying! I was experimenting with some deferred rendering versions of the builder but it inevitably ends up requiring lifetime constrains. It appears that in the way the builder is used now this could work out trivially, but I'll have to wrap my head around how to do it best. The current version of the library already has some optimizations, but it's far from trivial: The percent_encoding library itself requires a &str or &[u8], so right now, at least one throwaway string representation must be generated either way.

@suneettipirneni suneettipirneni changed the title refactor(http): Use query parameter builders refactor(http): Use query string helper May 27, 2024
@github-actions github-actions bot added the c-all Affects all crates or the project as a whole label May 27, 2024
Copy link
Member

@vilgotf vilgotf 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, just some code style questions.

twilight-http/src/lib.rs Outdated Show resolved Hide resolved
twilight-http/src/query_array.rs Outdated Show resolved Hide resolved
twilight-http/src/query_array.rs Outdated Show resolved Hide resolved
twilight-http/src/query_str_formatter.rs Outdated Show resolved Hide resolved
twilight-http/src/routing.rs Outdated Show resolved Hide resolved
twilight-http/src/routing.rs Outdated Show resolved Hide resolved
twilight-http/src/routing.rs Outdated Show resolved Hide resolved
twilight-http/src/routing.rs Outdated Show resolved Hide resolved
twilight-http/src/routing.rs Outdated Show resolved Hide resolved
twilight-http/src/routing.rs Outdated Show resolved Hide resolved
@suneettipirneni suneettipirneni merged commit 438ace0 into main May 31, 2024
9 checks passed
@suneettipirneni suneettipirneni deleted the refactor/query-builders branch May 31, 2024 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-all Affects all crates or the project as a whole c-http Affects the http crate t-refactor Refactors APIs or code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants