jump-dev / jump-dev/MutableArithmetics.jl

adding a small integer to a `BigInt` with `operate!` allocates

Open
#353 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
TeX
Stars
55
Forks
15
Avg merge
2d 21m
Merged PRs (30d)
2

Description

Presumably the small integer is being converted to `BigInt` by mistake. It is possible to add some small ints to a `BigInt` directly using `Base.GMP.MPZ.add_si!` (or `Base.GMP.MPZ.add_ui!`).

```julia-repl
julia> using MutableArithmetics: MutableArithmetics as MA

julia> x = BigInt(0)
0

julia> @timev MA.operate!(+, x, 1)
0.086091 seconds (135.80 k allocations: 7.078 MiB, 99.88% compilation time)
elapsed time (ns): 8.6090543e7
gc time (ns): 0
bytes allocated: 7421600
pool allocs: 135768
non-pool GC allocs: 1
malloc() calls: 34
realloc() calls: 1
free() calls: 0
minor collections: 0
full collections: 0
1

julia> @timev MA.operate!(+, x, 1)
0.000022 seconds (2 allocations: 56 bytes)
elapsed time (ns): 21772.0
gc time (ns): 0
bytes allocated: 56
pool allocs: 1
non-pool GC allocs: 0
malloc() calls: 1
free() calls: 0
minor collections: 0
full collections: 0
2
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.