Spanner Performance Improvements#2741
Merged
blowmage merged 4 commits intogoogleapis:masterfrom Dec 29, 2018
Merged
Conversation
This refactor seems to improve performance a bit.
Here are the benchmarks with GC disabled:
user system total real
Using pairs 0.204243 0.008495 0.212738 ( 0.213284)
Using to_a 0.196423 0.007768 0.204191 ( 0.204834)
This enhancement allows users to skip the dupplicate name check
when serializing Data to a Ruby Hash or Array.
This speeds up the serialization, but data may be lost.
Here are the benchmarks with GC disabled:
user system total real
With dup check 0.196423 0.007768 0.204191 ( 0.204834)
Without dup check 0.136929 0.007002 0.143931 ( 0.145008)
This refactor improves detection of duplicate names.
Here are the benchmarks with GC disabled:
user system total real
Using uniq 0.060000 0.000000 0.060000 ( 0.062388)
Using group_by 0.040000 0.000000 0.040000 ( 0.044493)
quartzmo
reviewed
Dec 28, 2018
| [key, value] | ||
| end | ||
| end | ||
| Hash[hashified_pairs] |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
quartzmo
reviewed
Dec 28, 2018
| # | ||
| # @param [Boolean] skip_dup_check Skip the check for whether nested data | ||
| # contains duplicate names. When skipped, the nested hash may lose | ||
| # values. Default is `false`. Optional. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| # hash. Do not use this method if the data has more than one member with | ||
| # the same name. | ||
| # hash. This method will raise or lose values if the data has more than | ||
| # one member with the same name. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
quartzmo
reviewed
Dec 28, 2018
| # | ||
| def duplicate_names? | ||
| keys.count != keys.uniq.count | ||
| keys.group_by { |e| e }.select { |_k, v| v.size > 1 }.any? |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
crwilcox
approved these changes
Dec 28, 2018
quartzmo
approved these changes
Dec 28, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We have received feedback that Spanner's serialization to a Ruby Hash is not as performant as expected. While there are micro-optimizations that can be made, the largest improvement in performance can be made by optionally skipping the check for duplicate names. Spanner data can contain duplicate names, or no names, which makes representing it in a Ruby Hash difficult. Consider the following example:
The former value of
:barwas dropped in favor of the latter value of:baz. To ensure that values are not dropped, Spanner data will raiseDuplicateNameErrorwhen serializing to a Ruby Hash. This PR adds the optionalskip_dup_checkargument that will avoid the check for users that want the most performance and are willing to manage the risk of losing values.Here are the performance numbers for master, the performance tweaks, and the performance tweaks with skipping the duplicate name check: