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 performance for materializing a string from a vector of Char #29551

Merged
merged 2 commits into from
Oct 12, 2018

Conversation

KristofferC
Copy link
Sponsor Member

@KristofferC KristofferC commented Oct 7, 2018

Before

julia> a = rand(Char, 10^4);

julia> @btime String(a);
  363.761 μs (6 allocations: 49.20 KiB)

After

julia> a = rand(Char, 10^4);

julia> @btime String(a);
  51.856 μs (1 allocation: 38.56 KiB)

The unrolling of the loop to write the char made a significant difference here (but is not where the major performance benefit comes from).

cc @bkamins

@KristofferC
Copy link
Sponsor Member Author

@nanosoldier runbenchmarks(ALL, vs = ":master")

@KristofferC
Copy link
Sponsor Member Author

@ararslan, any idea how nanosoldier is doing?

@ararslan
Copy link
Member

ararslan commented Oct 7, 2018

Hm, there were no errors in the log or anything, it just seemed to be stuck. I've restarted the server, so let's just try again. @nanosoldier runbenchmarks(ALL, vs=":master")

@@ -576,6 +576,19 @@ function unindent(str::AbstractString, indent::Int; tabwidth=8)
String(take!(buf))
end

function String(a::Vector{Char})
Copy link
Member

Choose a reason for hiding this comment

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

Maybe the signature could be a::AbstractVector{Char}?

@@ -145,6 +145,28 @@ end
string(a::String) = String(a)
string(a::SubString{String}) = String(a)

@inline function __string!(out, c::Char, offs::Integer)
Copy link
Member

Choose a reason for hiding this comment

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

maybe name it __unsafe_string! to highlight the fact that it does not perform bounds checking?

@nanosoldier
Copy link
Collaborator

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

Copy link
Sponsor Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

Looks like a good optimization, but I disagree that this should be backported.

@KristofferC
Copy link
Sponsor Member Author

fine

@ararslan
Copy link
Member

ararslan commented Oct 9, 2018

but I disagree that this should be backported.

Can you elaborate on why?

@StefanKarpinski
Copy link
Sponsor Member

Looks like a good optimization, but I disagree that this should be backported.

Why?

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

Successfully merging this pull request may close these issues.

None yet

6 participants