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

803 823 #904

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

803 823 #904

wants to merge 7 commits into from

Conversation

twmb
Copy link
Owner

@twmb twmb commented Feb 7, 2025

No description provided.

twmb added 4 commits February 5, 2025 12:16
Next commit will add options to override these two. This is the first
step towards exporting functionality that allows manually processing raw
fetch responses.
This slab allocates the records we will be creating, reducing the number
of allocs (and thus gc pressure), while keeping alloc size the sameish
(or reducing it a bit). This should address the main problem for 823,
but we can still add caching in a bit.

For #823.
twmb added 3 commits February 6, 2025 23:18
…esponses

This incorporates #803 with a few minor changes.

Thank you to @dimitarvdimitrov for the excellent contribution.

Closes #803.
This adds pools in the same manner that hooks exist: users can opt in to
any pool they wish. The decompress pool is the trickiest to implement --
and the trickiest to use if you implement your own decompressor.

TODO remains to add this to the request buffer.

Closes #803, #823.
Copy link

@dimitarvdimitrov dimitarvdimitrov left a comment

Choose a reason for hiding this comment

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

SGTM, I left a few small questions

// DefaultDecompressor returns the default decompressor used by clients.
// If a pool is provided and implements PoolDecompressBytes, it will be
// used.
func DefaultDecompressor(pools ...Pool) Decompressor {

Choose a reason for hiding this comment

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

is the intention here that only one pool is passed (and the function takes a variadic because that pool is optional)? It could be just a language thing, but that wasn't immediately clear to me.

Copy link
Owner Author

Choose a reason for hiding this comment

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

The first pool that implements PoolDecompressBytes will be used; the intention here is to allow the end user to use the same pools here that they use in the config option WithPools -- so, they can be a bit lazy if they have multiple separate pools rather than figure out which pool they should use.

Choose a reason for hiding this comment

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

ahaaa. Is it the first or the last? Currently the loop in decompressor.Decompress takes a slice for all implementations and keeps only the last one.

Maybe mention this behaviour in a brief comment here as this is a public function (or a validation function and not rely on humans/AI reading comments),

Copy link
Owner Author

Choose a reason for hiding this comment

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

Actually you're pointing out a bug -- the first pool that returns a slice should cause the each function to return early. I'm going to change each arg to func(Pool) bool, and if it returns true, stop iterating.

}

/*TODO
type PoolRequestBuffer interface {

Choose a reason for hiding this comment

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

did you mean to implement this in this PR or only later on?

Copy link
Owner Author

Choose a reason for hiding this comment

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

This will be implemented in this PR soon :)

return
}

// Reset the capacity of slices to max to ensure we zero things and

Choose a reason for hiding this comment

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

nitpick on the comment: this only resets the length of the slices, their capacity is still the same. Also the sentence in the comment isn't complete

var userPooled bool
d.pools.each(func(p Pool) {
if pdecompressBytes, ok := p.(PoolDecompressBytes); ok {
s := pdecompressBytes.GetDecompressBytes(src, codecType)

Choose a reason for hiding this comment

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

this will take a slice from every pool which implements the interface but will only return one. Should we add some safeguard this can't happen? Maybe some validation that there's at most one pool of each interface?

Copy link
Owner Author

Choose a reason for hiding this comment

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

This is a bug, have a fix locally that I'll push after adding the last pool.

// DefaultDecompressor returns the default decompressor used by clients.
// If a pool is provided and implements PoolDecompressBytes, it will be
// used.
func DefaultDecompressor(pools ...Pool) Decompressor {

Choose a reason for hiding this comment

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

ahaaa. Is it the first or the last? Currently the loop in decompressor.Decompress takes a slice for all implementations and keeps only the last one.

Maybe mention this behaviour in a brief comment here as this is a public function (or a validation function and not rely on humans/AI reading comments),

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