-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce generated functions: getindex (#28)
* Convert getindex(::Blob, ::Val{field}) from generated func. - The produced code is unchanged, and the perf remains the same. - This is tested by a new testitem * Eliminate another generated function: self_size! Managed via compiler annotations This new function is ~10x faster than the older `@generated` function: - ~10ms down to ~1ms * Reorganize to hopefully minimize the generated part of unsafe_store! * Recursion for computing blob_offset * Get unsafe_load() un-generated as well! :) * Bump to v1.1 * Switch unsafe_store! to non-generated as well. 2x slower, but less compile time so worth it. * Improve compile-time perf on self_size computation * De-val getindex, which fixes getproperty codegen. (Unclear why) ``` julia> @code_llvm debuginfo=:none (b->b.x)(b) define void @"julia_#35_644"([3 x i64]* noalias nocapture noundef nonnull sret([3 x i64]) align 8 dereferenceable(24) %0, [3 x i64]* nocapture noundef nonnull readonly align 8 dereferenceable(24) %1) #0 { top: %memcpy_refined_src1 = getelementptr inbounds [3 x i64], [3 x i64]* %1, i64 0, i64 2 %2 = load i64, i64* %memcpy_refined_src1, align 8 %3 = bitcast [3 x i64]* %1 to <2 x i64>* %4 = load <2 x i64>, <2 x i64>* %3, align 8 %5 = bitcast [3 x i64]* %0 to <2 x i64>* store <2 x i64> %4, <2 x i64>* %5, align 8 %newstruct.sroa.3.0..sroa_idx4 = getelementptr inbounds [3 x i64], [3 x i64]* %0, i64 0, i64 2 store i64 %2, i64* %newstruct.sroa.3.0..sroa_idx4, align 8 ret void } ``` * Force fieldidx to const-fold, even for large (100 field) structs According to @benchmark, this made compiling getproperty and setproperty for 100-field structs take 2ms longer (7ms -> 9ms) * Add tests for allocations * Noinline the function to actually throw the assertion --------- Co-authored-by: Sacha Verweij <[email protected]>
- Loading branch information
Showing
3 changed files
with
181 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
@testitem "type-stability" begin | ||
using BenchmarkTools | ||
|
||
struct Quux | ||
x::BlobVector{Int} | ||
y::Float64 | ||
end | ||
struct Bar | ||
a::Int | ||
b::BlobBitVector | ||
c::Bool | ||
d::BlobVector{Float64} | ||
e::Blob{Quux} | ||
end | ||
|
||
@test Blobs.self_size(Bar) == 8 + 16 + 1 + 16 + 8 # Blob{Quux} is smaller in the blob | ||
|
||
function Blobs.child_size(::Type{Quux}, x_len::Int64, y::Float64) | ||
T = Quux | ||
+(Blobs.child_size(fieldtype(T, :x), x_len)) | ||
end | ||
|
||
function Blobs.child_size(::Type{Bar}, b_len::Int64, c::Bool, d_len::Int64, e_len::Int64, y::Float64) | ||
T = Bar | ||
+(Blobs.child_size(fieldtype(T, :b), b_len), | ||
Blobs.child_size(fieldtype(T, :d), d_len), | ||
Blobs.child_size(fieldtype(T, :e), e_len, y)) | ||
end | ||
|
||
function Blobs.init(quux::Blob{Quux}, free::Blob{Nothing}, x_len::Int64, y::Float64) | ||
free = Blobs.init(quux.x, free, x_len) | ||
quux.y[] = y | ||
free | ||
end | ||
|
||
function Blobs.init(bar::Blob{Bar}, free::Blob{Nothing}, b_len::Int64, c::Bool, d_len::Int64, e_len::Int64, y::Float64) | ||
free = Blobs.init(bar.b, free, b_len) | ||
free = Blobs.init(bar.d, free, d_len) | ||
free = Blobs.init(bar.e, free, e_len, y) | ||
bar.c[] = c | ||
free | ||
end | ||
|
||
bar = Blobs.malloc_and_init(Bar, 10, false, 20, 15, 1.5) | ||
|
||
# Test type stability | ||
test_getproperty1(b) = b.e | ||
test_getproperty2(b) = b.d | ||
@testset "getindex" begin | ||
@test @inferred(test_getproperty1(bar)) === bar.e | ||
@test @ballocated(test_getproperty1($bar)) === 0 | ||
@test @inferred(test_getproperty2(bar)) === bar.d | ||
@test @ballocated(test_getproperty2($bar)) === 0 | ||
end | ||
|
||
@testset "unsafe_load" begin | ||
@test @inferred(unsafe_load(bar)) isa Bar | ||
@test @ballocated(unsafe_load($bar)) === 0 | ||
end | ||
|
||
@testset "self_size" begin | ||
@test @inferred(Blobs.self_size(Bar)) === 49 | ||
@test @ballocated(Blobs.self_size(Bar)) === 0 | ||
end | ||
|
||
@testset "unsafe_store!" begin | ||
bar_value = unsafe_load(bar) | ||
@test @inferred(Blobs.unsafe_store!(bar, bar_value)) isa Bar | ||
@test @ballocated(Blobs.unsafe_store!($bar, $bar_value)) === 0 | ||
end | ||
|
||
read_and_write(bar) = (bar.e[].y[] = bar.a[]) | ||
@testset "load & store" begin | ||
@test @inferred(read_and_write(bar)) isa Int | ||
@test @ballocated(read_and_write($bar)) === 0 | ||
end | ||
end |
9773e2b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register()
9773e2b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/123214
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:
Also, note the warning: Version 1.1.0 skips over 1.0.0
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.