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 string range indexing #29796

Merged
merged 1 commit into from
Oct 27, 2018
Merged

Conversation

KristofferC
Copy link
Member

@KristofferC KristofferC commented Oct 25, 2018

using BenchmarkTools
using Random
using BenchmarkTools
s = randstring(200)
f_ib(s) = @inbounds s[1:100]
f(s) = s[1:100]

Master

julia> @btime f($s);
  103.603 ns (1 allocation: 128 bytes)

julia> @btime f_ib($s);
  103.692 ns (1 allocation: 128 bytes)

PR

julia> @btime f($s);
  37.007 ns (1 allocation: 128 bytes)

julia> @btime f_ib($s);
  25.304 ns (1 allocation: 128 bytes)

Not sure we have any Nanosoldier for this but might as well

Also added some @inline where functions expected themselves to get inlined (since they used @boundscheck).

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

@KristofferC KristofferC added performance Must go faster strings "Strings!" labels Oct 25, 2018
@KristofferC KristofferC changed the title improve performance for string indexing improve performance for string range indexing Oct 25, 2018
@KristofferC
Copy link
Member Author

Made some changes, fire off another one

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

return ss
end

function length(s::String, i::Int, j::Int)
@inline function length(s::String, i::Int, j::Int)
Copy link
Member

Choose a reason for hiding this comment

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

Ref #29798

@nanosoldier
Copy link
Collaborator

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

@nanosoldier
Copy link
Collaborator

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

@KristofferC KristofferC added the potential benchmark Could make a good benchmark in BaseBenchmarks label Oct 25, 2018
@KristofferC
Copy link
Member Author

KristofferC commented Oct 25, 2018

I checked the small memory regression in spellcheck and it seems to occur when getindex with a range is inlined but only in the very specific case when the range indexing of a string is inside a double comprehension. Rewriting the benchmark to avoid this apparently pathological case the performance is better and since we now can use @inbounds it is significantly better if that is used.

I am therefore of the opinion that this regression is acceptable and that in other code the benefit of inlining getindex is worth it. Will merge in a few days unless someone objects to the analysis above.

@KristofferC KristofferC merged commit 1038233 into master Oct 27, 2018
@fredrikekre fredrikekre deleted the kc/string_indexing branch October 27, 2018 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster potential benchmark Could make a good benchmark in BaseBenchmarks strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants