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

isbits is slow? #3938

Closed
vtjnash opened this issue Aug 4, 2013 · 3 comments
Closed

isbits is slow? #3938

vtjnash opened this issue Aug 4, 2013 · 3 comments
Labels
performance Must go faster

Comments

@vtjnash
Copy link
Sponsor Member

vtjnash commented Aug 4, 2013

julia> x = [1:100]

julia> @sprofile for i = 1:1e7 copy!(x, x) end

julia> Profile.sprofile_tree()
     819 client.jl; _start; line: 372
      819 client.jl; run_repl; line: 166
         819 client.jl; eval_user_input; line: 91
            769 /Users/jameson/.julia/Profile/src/sprofile.jl; anonymous; line: 1
              578 array.jl; copy!; line: 64
               9   array.jl; copy!; line: 58
               549 array.jl; copy!; line: 61
                502 array.jl; unsafe_copy!; line: 47
                 470 reflection.jl; isbits; line: 36
                32  array.jl; unsafe_copy!; line: 48
                 15 array.jl; unsafe_copy!; line: 41
                 4  array.jl; unsafe_copy!; line: 43
                11  array.jl; unsafe_copy!; line: 54
                2   reflection.jl; isbits; line: 36
            43  /Users/jameson/.julia/Profile/src/sprofile.jl; anonymous; line: 309

julia> sprofile_clear()

Similarly using setindex! notation, although the creation of the colon object is about equally expensive.

julia> @sprofile for i = 1:1e7 x[:] = x end

julia> Profile.sprofile_tree()
     1564 client.jl; _start; line: 372
      1564 client.jl; run_repl; line: 166
         1564 client.jl; eval_user_input; line: 91
            1524 /Users/jameson/.julia/Profile/src/sprofile.jl; anonymous; line: 1
              1    array.jl; setindex!; line: 433
              1    range.jl; colon; line: 38
               5   abstractarray.jl; endof; line: 25
               14  array.jl; setindex!; line: 431
               566 array.jl; setindex!; line: 432
                9   array.jl; copy!; line: 58
                556 array.jl; copy!; line: 61
                 501 array.jl; unsafe_copy!; line: 47
                  460 reflection.jl; isbits; line: 36
                 40  array.jl; unsafe_copy!; line: 48
                  18 array.jl; unsafe_copy!; line: 41
                  10 array.jl; unsafe_copy!; line: 43
                 7   array.jl; unsafe_copy!; line: 54
                 1   reflection.jl; isbits; line: 36
               9   array.jl; setindex!; line: 433
               4   promotion.jl; max; line: 189
               1   range.jl; Range1; line: 28
               43  range.jl; colon; line: 38
                10 promotion.jl; max; line: 189
                6  range.jl; Range1; line: 27
                7  range.jl; Range1; line: 28
            21   /Users/jameson/.julia/Profile/src/sprofile.jl; anonymous; line: 309
@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Aug 7, 2013

It appears to now be inline, but still is allocating a new box for the result.

(edit: code added)

julia> f() = isbits(Int)
# methods for generic function f
f() at none:1

julia> finfer(f,())
:($(Expr(:lambda, {}, {{},{},{}}, quote  # none, line 1:
        return top(box)(Bool,top(and_int)(top(box)(Bool,top(not_int)(top(getfield)(Int,:mutable)::Bool))::Bool,top(getfield)(Int,:pointerfree)::Bool))::Bool
    end)))

julia> f()
true

julia> disassemble(f,())
WARNING: disassemble(f::Function,t::Tuple) is deprecated, use code_llvm(f,t) instead.

define i1 @julia_f1097() {
top:
  %0 = alloca [4 x %jl_value_t*], align 8
  %.sub = getelementptr inbounds [4 x %jl_value_t*]* %0, i64 0, i64 0
  %1 = getelementptr [4 x %jl_value_t*]* %0, i64 0, i64 2, !dbg !5659
  store %jl_value_t* inttoptr (i64 4 to %jl_value_t*), %jl_value_t** %.sub, align 8
  %2 = load %jl_value_t*** @jl_pgcstack, align 8, !dbg !5659
  %3 = getelementptr [4 x %jl_value_t*]* %0, i64 0, i64 1, !dbg !5659
  %.c = bitcast %jl_value_t** %2 to %jl_value_t*, !dbg !5659
  store %jl_value_t* %.c, %jl_value_t** %3, align 8, !dbg !5659
  store %jl_value_t** %.sub, %jl_value_t*** @jl_pgcstack, align 8, !dbg !5659
  store %jl_value_t* null, %jl_value_t** %1, align 8
  %4 = getelementptr [4 x %jl_value_t*]* %0, i64 0, i64 3
  store %jl_value_t* null, %jl_value_t** %4, align 8
  %5 = load %jl_value_t** inttoptr (i64 4346643568 to %jl_value_t**), align 16, !dbg !5664
  store %jl_value_t* %5, %jl_value_t** %1, align 8, !dbg !5664
  store %jl_value_t* inttoptr (i64 4313910528 to %jl_value_t*), %jl_value_t** %4, align 8, !dbg !5664
  %6 = call %jl_value_t* @jl_f_get_field(%jl_value_t* null, %jl_value_t** %1, i32 2), !dbg !5664
  %7 = getelementptr inbounds %jl_value_t* %6, i64 1, i32 0, !dbg !5664
  %8 = bitcast %jl_value_t** %7 to i8*, !dbg !5664
  %9 = load i8* %8, align 1, !dbg !5664
  %10 = and i8 %9, 1, !dbg !5664
  %11 = icmp eq i8 %10, 0, !dbg !5664
  %12 = load %jl_value_t** inttoptr (i64 4346643568 to %jl_value_t**), align 16, !dbg !5664
  store %jl_value_t* %12, %jl_value_t** %1, align 8, !dbg !5664
  store %jl_value_t* inttoptr (i64 4313910576 to %jl_value_t*), %jl_value_t** %4, align 8, !dbg !5664
  %13 = call %jl_value_t* @jl_f_get_field(%jl_value_t* null, %jl_value_t** %1, i32 2), !dbg !5664
  %14 = getelementptr inbounds %jl_value_t* %13, i64 1, i32 0, !dbg !5664
  %15 = bitcast %jl_value_t** %14 to i8*, !dbg !5664
  %16 = load i8* %15, align 1, !dbg !5664
  %17 = and i8 %16, 1, !dbg !5664
  %18 = icmp ne i8 %17, 0, !dbg !5664
  %19 = and i1 %11, %18, !dbg !5664
  %20 = load %jl_value_t** %3, align 8, !dbg !5664
  %21 = getelementptr inbounds %jl_value_t* %20, i64 0, i32 0, !dbg !5664
  store %jl_value_t** %21, %jl_value_t*** @jl_pgcstack, align 8, !dbg !5664
  ret i1 %19, !dbg !5664
}

@vtjnash vtjnash reopened this Aug 7, 2013
@JeffBezanson
Copy link
Sponsor Member

I don't see any allocations there.

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Aug 7, 2013

jl_f_get_field has to allocate a box for the return value (is this a general problem with emit_getfield?)

KristofferC pushed a commit that referenced this issue Jul 26, 2024
Stdlib: Pkg
URL: https://github.com/JuliaLang/Pkg.jl.git
Stdlib branch: master
Julia branch: master
Old commit: 6b4394914
New commit: e4a6723bf
Julia version: 1.12.0-DEV
Pkg version: 1.12.0
Bump invoked by: @IanButterworth
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/Pkg.jl@6b43949...e4a6723

```
$ git log --oneline 6b4394914..e4a6723bf
e4a6723bf Use `Base.TOML.Parser{Dates}` for TOML parsing w/ Dates support (#3938)
8c1f45d98 Append bundled depots to places where we empty it during tests (#3807)
2fdfabaf5 Test fixes (#3972)
34bb51ece fix bad depot path setting (#3971)
3715685b9 fix suggestions threshold for printing (#3968)
3f81d6c4d feat: add JULIA_PKG_GC_AUTO env var (#3642)
fad26d7f2 check `project_file` isa String (#3967)
8875120ad fix not hardcoding "Project.toml" when fixing up extensions in manifest (#3851)
90d42a1b0 Make manifest usage log errors non-fatal (#3962)
```

Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
lazarusA pushed a commit to lazarusA/julia that referenced this issue Aug 17, 2024
…#55258)

Stdlib: Pkg
URL: https://github.com/JuliaLang/Pkg.jl.git
Stdlib branch: master
Julia branch: master
Old commit: 6b4394914
New commit: e4a6723bf
Julia version: 1.12.0-DEV
Pkg version: 1.12.0
Bump invoked by: @IanButterworth
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/Pkg.jl@6b43949...e4a6723

```
$ git log --oneline 6b4394914..e4a6723bf
e4a6723bf Use `Base.TOML.Parser{Dates}` for TOML parsing w/ Dates support (JuliaLang#3938)
8c1f45d98 Append bundled depots to places where we empty it during tests (JuliaLang#3807)
2fdfabaf5 Test fixes (JuliaLang#3972)
34bb51ece fix bad depot path setting (JuliaLang#3971)
3715685b9 fix suggestions threshold for printing (JuliaLang#3968)
3f81d6c4d feat: add JULIA_PKG_GC_AUTO env var (JuliaLang#3642)
fad26d7f2 check `project_file` isa String (JuliaLang#3967)
8875120ad fix not hardcoding "Project.toml" when fixing up extensions in manifest (JuliaLang#3851)
90d42a1b0 Make manifest usage log errors non-fatal (JuliaLang#3962)
```

Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
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

2 participants