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

Reduce allocations during conversion, enable new UnsafeConvertToVersion path #25018

Merged
merged 4 commits into from
May 12, 2016

Conversation

smarterclayton
Copy link
Contributor

Cleans up the conversion path to avoid a few unnecessary allocations, then creates a new UnsafeConvertToVersion path that will allow encode/decode to bypass copying the object for performance. In that subsequent PR, ConvertToVersion will start to call Copy() and we will refactor conversions to reuse as much of the existing object as possible.

Also changes the unversioned.ObjectKind signature to not require allocations - speeds up a few common paths.

@smarterclayton smarterclayton added the sig/scalability Categorizes an issue or PR as relevant to SIG Scalability. label May 1, 2016
@smarterclayton
Copy link
Contributor Author

@wojtek-t @kubernetes/sig-api-machinery this is a bunch of prep refactors to enable the big performance gains on encoding / decoding by reusing types that are identical

@k8s-github-robot k8s-github-robot added kind/new-api size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 1, 2016
@smarterclayton smarterclayton added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels May 1, 2016
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 2, 2016
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 5, 2016
@k8s-github-robot k8s-github-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 5, 2016
@smarterclayton
Copy link
Contributor Author

@wojtek-t in case this dropped off your radar

@k8s-github-robot k8s-github-robot assigned deads2k and unassigned lavalamp May 6, 2016
@@ -69,7 +69,7 @@ func NewCodecForScheme(
encodeVersion []unversioned.GroupVersion,
decodeVersion []unversioned.GroupVersion,
) runtime.Codec {
return NewCodec(encoder, decoder, scheme, scheme, scheme, runtime.ObjectTyperToTyper(scheme), encodeVersion, decodeVersion)
return NewCodec(encoder, decoder, runtime.UnsafeObjectConvertor(scheme), scheme, scheme, runtime.ObjectTyperToTyper(scheme), encodeVersion, decodeVersion)
Copy link
Contributor

Choose a reason for hiding this comment

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

So are we assuming this safe by default since during a conversion step every sane thing I can think of throws away the original or is there some reason I'm not seeing that makes this always safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you are using a versioning codec, conversion is always "create
intermediate and then throw it away". If you don't run conversion, then we
guarantee not to mutate your object, unless you give us an object that
mutates itself during serialization, in which case we hate you and you
deserve what you get.

On Fri, May 6, 2016 at 4:05 PM, David Eads notifications@github.com wrote:

In pkg/runtime/serializer/versioning/versioning.go
#25018 (comment)
:

@@ -69,7 +69,7 @@ func NewCodecForScheme(
encodeVersion []unversioned.GroupVersion,
decodeVersion []unversioned.GroupVersion,
) runtime.Codec {

  • return NewCodec(encoder, decoder, scheme, scheme, scheme, runtime.ObjectTyperToTyper(scheme), encodeVersion, decodeVersion)
  • return NewCodec(encoder, decoder, runtime.UnsafeObjectConvertor(scheme), scheme, scheme, runtime.ObjectTyperToTyper(scheme), encodeVersion, decodeVersion)

So are we assuming this safe by default since during a conversion step
every sane thing I can think of throws away the original or is there some
reason I'm not seeing that makes this always safe?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/kubernetes/kubernetes/pull/25018/files/ca669c5de0eba299d027ecb1c9d32155ef058038#r62383689

@wojtek-t
Copy link
Member

wojtek-t commented May 7, 2016

@smarterclayton - sorry I completely missed this PR. I will take a look on Monday.

return nil, fmt.Errorf("%v is not a registered type and cannot be converted into version %q", t, outVersion)
}

// if the Go type is also registered to the destination kind, no conversion is necessary
Copy link
Member

Choose a reason for hiding this comment

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

hmm - I don't understand it. Can you please clarify what are you doing here?

Copy link
Member

Choose a reason for hiding this comment

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

Do I understand correctly that it basically mean that exactly the same type is basically registered in few different group versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wojtek-t wojtek-t assigned wojtek-t and unassigned deads2k May 10, 2016
@wojtek-t
Copy link
Member

Some minor comments - feel free to self-apply lgtm label after addressing/answering them.

@smarterclayton
Copy link
Contributor Author

Comment applied, rebased, reapplying LGTM

@smarterclayton smarterclayton added lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. labels May 10, 2016
@smarterclayton
Copy link
Contributor Author

Bumping to P2 since this blocks the new "fast conversion" work.

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 10, 2016
@wojtek-t wojtek-t added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 10, 2016
@wojtek-t
Copy link
Member

LGTM

We will probably readd these as an opaque object passed down to
conversions that lets the caller get access to more info (like
a negotiated serializer).
We don't need to pass a pointer into SetGroupKindVersion() - a
struct works just as well.
Long delayed refactor, avoids a few more allocations.
Only encode/decode will call this path, to allow us to optimize for
unsafe operations.
@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 12, 2016
@smarterclayton smarterclayton added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 12, 2016
@smarterclayton
Copy link
Contributor Author

Trivial rebase

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link

k8s-bot commented May 12, 2016

GCE e2e build/test passed for commit ea7e7a1.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 5c30f98 into kubernetes:master May 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note-none Denotes a PR that doesn't merit a release note. sig/scalability Categorizes an issue or PR as relevant to SIG Scalability. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants