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

improve perf for string with both strings and chars as argument #27691

Merged
merged 1 commit into from
Jun 23, 2018

Conversation

KristofferC
Copy link
Member

@KristofferC KristofferC commented Jun 20, 2018

Before:

julia> @btime string("foo", 'b', "ar")
  443.838 ns (8 allocations: 288 bytes)

After

julia> @btime string("Foo", 'b', "ar")
  110.836 ns (3 allocations: 192 bytes)

Ref #27030 (comment)

@KristofferC KristofferC added performance Must go faster strings "Strings!" labels Jun 20, 2018
@KristofferC

This comment has been minimized.

@nanosoldier

This comment has been minimized.

@ararslan

This comment has been minimized.

@KristofferC

This comment has been minimized.

@ararslan

This comment has been minimized.

@nanosoldier

This comment has been minimized.

@KristofferC
Copy link
Member Author

@nanosoldier runbenchmarks("shootout" || "string" || "problem", vs=":master")

@KristofferC
Copy link
Member Author

KristofferC commented Jun 21, 2018

This is still 3x slower than 0.6 though (instead of 12).

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - no performance regressions were detected. A full report can be found here. cc @ararslan

@KristofferC KristofferC reopened this Jun 22, 2018
end
return String(resize!(io.data, io.size))
Copy link
Member

Choose a reason for hiding this comment

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

Why not String(take!(io))?

Copy link
Member

Choose a reason for hiding this comment

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

This consumes the data rather than making a copy.

Copy link
Member

@mbauman mbauman Jun 22, 2018

Choose a reason for hiding this comment

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

In this case, take! behaves the same way and doesn't make a copy. Ah, but I do understand now, the issue is that take! also is preparing the IOBuffer for additional writes, and allocates a new buffer to replace the one that becomes the string.

In Kristoffer's @btime string("foo", 'b', "ar"), this incurs a 30% penalty. Alright, carry on.

Copy link
Member

Choose a reason for hiding this comment

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

I wish take! didn't do that. In the vast majority (all?) of cases, an IOBuffer is not used after take! is called, so we should at least optimize for that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened #27741

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants