MasonProtter / Bumper.jl

Bring Your Own Stack
MIT License
152 stars 6 forks source link

Adjust size heuristics #30

Closed MasonProtter closed 8 months ago

MasonProtter commented 8 months ago

I think 1mb is a bit more reasonable. This is also the size where Julia itself starts turning stack allocations into heap allocations:

julia> code_llvm(Tuple{}, debuginfo=:none) do
           r = Ref{NTuple{1_048_575, UInt8}}()
           Base.donotdelete(r)
       end
define void @"julia_#16_1305"() #0 {
top:
  %0 = alloca [1048575 x i8], align 16
  call void (...) @jl_f_donotdelete([1048575 x i8]* nonnull %0)
  ret void
}

versus

julia> code_llvm(Tuple{}, debuginfo=:none) do
           r = Ref{NTuple{1_048_576, UInt8}}()
           Base.donotdelete(r)
       end
define void @"julia_#14_1303"() #0 {
top:
  %thread_ptr = call i8* asm "movq %fs:0, $0", "=r"() #9
  %tls_ppgcstack = getelementptr i8, i8* %thread_ptr, i64 -8
  %0 = bitcast i8* %tls_ppgcstack to {}****
  %tls_pgcstack = load {}***, {}**** %0, align 8
  %ptls_field3 = getelementptr inbounds {}**, {}*** %tls_pgcstack, i64 2
  %1 = bitcast {}*** %ptls_field3 to i8**
  %ptls_load45 = load i8*, i8** %1, align 8
  %newstruct = call noalias nonnull dereferenceable(1048584) {}* @ijl_gc_big_alloc(i8* %ptls_load45, i64 1048584) #6
  %2 = bitcast {}* %newstruct to i64*
  %3 = getelementptr inbounds i64, i64* %2, i64 -1
  store atomic i64 139861397231184, i64* %3 unordered, align 8
  call void (...) @jl_f_donotdelete({}* nonnull %newstruct)
  ret void
}