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

Audit gc root allocations for exceptions in small functions? #23281

Open
KristofferC opened this issue Aug 16, 2017 · 2 comments
Open

Audit gc root allocations for exceptions in small functions? #23281

KristofferC opened this issue Aug 16, 2017 · 2 comments
Labels
performance Must go faster

Comments

@KristofferC
Copy link
Sponsor Member

KristofferC commented Aug 16, 2017

There are places in Base where manually outlining error throwing can give significant (relative) speedups. For example, changing

julia/base/parse.jl

Lines 7 to 15 in bdd0e99

function parse(::Type{T}, c::Char, base::Integer=36) where T<:Integer
a::Int = (base <= 36 ? 10 : 36)
2 <= base <= 62 || throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base"))
d = '0' <= c <= '9' ? c-'0' :
'A' <= c <= 'Z' ? c-'A'+10 :
'a' <= c <= 'z' ? c-'a'+a : throw(ArgumentError("invalid digit: $(repr(c))"))
d < base || throw(ArgumentError("invalid base $base digit $(repr(c))"))
convert(T, d)
end
to:

function parse2(::Type{T}, c::Char, base::Integer=36) where T<:Integer
    a::Int = (base <= 36 ? 10 : 36)
    2 <= base <= 62 || throw_invalid_base(base)
    d = '0' <= c <= '9' ? c-'0'    :
        'A' <= c <= 'Z' ? c-'A'+10 :
        'a' <= c <= 'z' ? c-'a'+a  : throw_invalid_digit(c)
    d < base || throw_invalid_base_digit(base, c)
    convert(T, d)
end

@noinline throw_invalid_base(base) = throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base"))
@noinline throw_invalid_digit(c) = throw(ArgumentError("invalid digit: $(repr(c))"))
@noinline throw_invalid_base_digit(base, c) = throw(ArgumentError("invalid base $base digit $(repr(c))"))

has a measurable impact:

julia> @btime parse2(Int64, 'a', 36);
  3.864 ns (0 allocations: 0 bytes)

julia> @btime parse(Int64, 'a', 36);
  5.422 ns (0 allocations: 0 bytes)

Is it worth to go through these type of functions and manually outline the error throwing, or is the plan to deal with all of that in another way which does not require manually moving them out?

@KristofferC KristofferC added the performance Must go faster label Aug 16, 2017
@yuyichao
Copy link
Contributor

is the plan to deal with all of that in another way which does not require manually moving them out?

Yes.

@Sacha0
Copy link
Member

Sacha0 commented Aug 16, 2017

Ref. potentially related #22210 (comment) and #22210 (comment). Best!

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

No branches or pull requests

3 participants