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

Speculative optimization: Use custom string serializer for Type #192

Merged
merged 1 commit into from Mar 28, 2019

Conversation

kyessenov
Copy link
Collaborator

It seems that the generic text proto CompactStringMarshal is more expensive that hand-made one.
Looking for feedback. I think we probably want to use a Struct as a hashmap key, but that would require building a new family of structs mirroring Types, since using proto Type does not seem to work.

It seems that the generic text proto CompactStringMarshal is more expensive that hand-made one.
@TristonianJones
Copy link
Collaborator

I'm not necessarily opposed to the change, but could you give more context about the expected impact/benefit to tests, execution, and performance?

@kyessenov
Copy link
Collaborator Author

Sure:

  • prior:
Benchmark             300         324989142 ns/op        46162742 B/op    1151582 allocs/op
  • after:
Benchmark            2000          64968044 ns/op        11220121 B/op     377465 allocs/op

@kyessenov
Copy link
Collaborator Author

The reason seems to be excessive allocations caused by standard protobuf. String() indirectly marshals the protos, and the mashaller is fairly expensive.

@TristonianJones
Copy link
Collaborator

TristonianJones commented Mar 28, 2019

Thanks for the info. Let's merge it as long as it doesn't impact the checking logic in any way.

@TristonianJones TristonianJones self-requested a review March 28, 2019 20:08
@kyessenov kyessenov changed the title Use custom string serializer for Type Speculative optimization: Use custom string serializer for Type Mar 28, 2019
@kyessenov
Copy link
Collaborator Author

I examined FormatCheckedType and it seems to be creating unique strings for distinct types. That assumes no obvious collisions, such as naming a proto "dyn". Let me know if you want to extend this further to disambiguate between proto "dyn" and dynamic "dyn".

Copy link
Collaborator

@TristonianJones TristonianJones left a comment

Choose a reason for hiding this comment

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

I don't think there's any need to differentiate the dyn types. They should be treated identically here.

@kyessenov
Copy link
Collaborator Author

Sorry, I wasn't clear. I can in theory create a proto with:

message dyn { }

in which case "dyn" is ambiguous between object type "dyn" and type "dyn". Frankly, noone should do it, but we can be more cautious in this function.

@TristonianJones
Copy link
Collaborator

TristonianJones commented Mar 28, 2019 via email

@kyessenov kyessenov merged commit 1791d15 into google:master Mar 28, 2019
@kyessenov
Copy link
Collaborator Author

Doing something like that will cause "check" to misbehave and reject the expression, so I guess the outcome is right -- don'to do nutty things.

@kyessenov kyessenov deleted the patch-1 branch March 28, 2019 21:28
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.

None yet

2 participants