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 of print(DevNull, x) #20830

Merged
merged 2 commits into from
Feb 28, 2017

Conversation

TotalVerb
Copy link
Contributor

We add a specialization of unsafe_write for DevNullStream and modify write to avoid a sgt -1 check which throws an exception on failure. The second change is safe because the len field of a string can be assumed to be a nonnegative integer, and indeed is already assumed to be nonnegative in other places.

Before:

julia> @benchmark print(DevNull, "foo")
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     5.974 ns (0.00% GC)
  median time:      5.982 ns (0.00% GC)
  mean time:        6.090 ns (0.00% GC)
  maximum time:     20.814 ns (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     1000
  time tolerance:   5.00%
  memory tolerance: 1.00%

After:

julia> @benchmark print(DevNull, "foo")
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     1.925 ns (0.00% GC)
  median time:      1.933 ns (0.00% GC)
  mean time:        1.978 ns (0.00% GC)
  maximum time:     13.797 ns (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     1000
  time tolerance:   5.00%
  memory tolerance: 1.00%

in particular,

julia> @code_llvm print(DevNull, "foo")

define void @julia_print_68274(i8**) #0 !dbg !5 {
top:
  ret void
}

@kshyatt kshyatt added display and printing Aesthetics and correctness of printed representations of objects. performance Must go faster labels Feb 27, 2017
@JeffBezanson JeffBezanson added the io Involving the I/O subsystem: libuv, read, write, etc. label Feb 28, 2017
@JeffBezanson JeffBezanson merged commit b1242df into JuliaLang:master Feb 28, 2017
@@ -68,7 +68,7 @@ codeunit(s::AbstractString, i::Integer)
unsafe_load(pointer(s),i)
end

write(io::IO, s::String) = unsafe_write(io, pointer(s), UInt(s.len))
write(io::IO, s::String) = unsafe_write(io, pointer(s), reinterpret(UInt, s.len))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe s.len % UInt?

@TotalVerb TotalVerb deleted the fw/reinterpret-uint branch March 1, 2017 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects. io Involving the I/O subsystem: libuv, read, write, etc. performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants