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

promhttp: Bite the bullet and implement all 32 possible interface combos #308

Merged
merged 1 commit into from
Jun 6, 2017

Conversation

beorn7
Copy link
Member

@beorn7 beorn7 commented Jun 2, 2017

@stuartnelson3 This is crazy…

As it turned out, it's not that esay to guess "common" combination of
interface upgrades. So I decided to just implement all 32 possible
combination of interface upgrades. (Only 16 with Go 1.7 and earlier.)

Clearly, this calls for code generation. But right now, we still need
to find out what's the best form of the code. For later additions,
implementing code generation might be useful.

Note that newDelegator is called for each HTTP request. Thus, this
commit aims to make the upgrade selection quick. (After the type
checks, it's just directly accessing an element in a slice.)

As it turned out, it's not that esay to guess "common" combination of
interface upgrades. So I decided to just implement all 32 possible
combination of interface upgrades. (Only 16 with Go 1.7 and earlier.)

Clearly, this calls for code generation. But right now, we still need
to find out what's the best form of the code. For later additions,
implementing code generation might be useful.

Note that newDelegator is called for each HTTP request. Thus, this
commit aims to make the upgrade selection quick. (After the type
checks, it's just directly accessing an element in a slice.)
@beorn7
Copy link
Member Author

beorn7 commented Jun 2, 2017

Fixes #272.

Copy link
Contributor

@stuartnelson3 stuartnelson3 left a comment

Choose a reason for hiding this comment

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

Thanks for doing this. I doubt the overhead is very much, since it is only incrementing a number and then indexing into the slice of delegators that's created initially.

id += readerFrom
}
if _, ok := w.(http.Pusher); ok {
id += pusher
Copy link
Contributor

Choose a reason for hiding this comment

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

clever

@beorn7
Copy link
Member Author

beorn7 commented Jun 6, 2017

Thanks for doing this. I doubt the overhead is very much, since it is only incrementing a number and then indexing into the slice of delegators that's created initially.

Yes, that's the idea: Minimize the overhead at runtime by having a lot of static code. What I did manually here is similar to things the C++ compiler does based on templates, so you can imagine where the infamous binary code bloat of C++ comes from.

@beorn7 beorn7 merged commit de4d4ff into master Jun 6, 2017
@beorn7 beorn7 deleted the beorn7/http branch June 6, 2017 10:22
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