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

marshal: use passed in byte slice if available. #1167

Merged
merged 1 commit into from
Aug 27, 2018

Conversation

Zariel
Copy link
Contributor

@Zariel Zariel commented Aug 27, 2018

We don't aloways need to allocate a new slice to unmarshal into when the
passed in one is available.

name                old time/op    new time/op    delta
UnmarshalVarchar-4     280ns ± 3%      75ns ± 4%  -73.23%  (p=0.000 n=18+19)

name                old alloc/op   new alloc/op   delta
UnmarshalVarchar-4    1.06kB ± 0%    0.03kB ± 0%  -96.97%  (p=0.000 n=20+20)

name                old allocs/op  new allocs/op  delta
UnmarshalVarchar-4      2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.000 n=20+20)

We don't aloways need to allocate a new slice to unmarshal into when the
passed in one is available.

```
name                old time/op    new time/op    delta
UnmarshalVarchar-4     280ns ± 3%      75ns ± 4%  -73.23%  (p=0.000 n=18+19)

name                old alloc/op   new alloc/op   delta
UnmarshalVarchar-4    1.06kB ± 0%    0.03kB ± 0%  -96.97%  (p=0.000 n=20+20)

name                old allocs/op  new allocs/op  delta
UnmarshalVarchar-4      2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.000 n=20+20)
```
@Zariel
Copy link
Contributor Author

Zariel commented Aug 27, 2018

cc @Dieterbe

@Dieterbe
Copy link
Contributor

Dieterbe commented Aug 27, 2018

<3 <3 thanks !

context for those who wonder: https://groups.google.com/forum/#!topic/gocql/ng0d9ZyGwSU

@Zariel Zariel merged commit f596bd3 into apache:master Aug 27, 2018
@Zariel Zariel deleted the unmarshal-bytes-strings-into-dest branch August 27, 2018 14:27
@Dieterbe
Copy link
Contributor

perhaps to be safe we should also have a benchmark comparing the case where nil is passed in. might it be slower due to the type assertion in the new code?

(not sure if this is useful or not, i plan to pass in non-nil slices..)

@Zariel
Copy link
Contributor Author

Zariel commented Aug 27, 2018

There shouldn't be any difference any way, it's also not possible to unmarshal into (*[]byte)(nil)

@Dieterbe
Copy link
Contributor

not sure what you mean, we've been passing a nil []byte so far and it works fine, and i imagine many other users do as well.
while we will adopt the optimized the approach, my point is we should still support nil (and probably confirm it doesn't perform worse with the patch applied)

@Zariel
Copy link
Contributor Author

Zariel commented Aug 27, 2018

There isn't any functional change other than it using the passed in slice.

Scanning into

var b []byte
iter.Scan(&b)

still works as the slice is not nil it is empty, a nil pointer to a slice can't be used.

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