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

Repeated allocation instances #7

Closed
baggepinnen opened this issue Oct 9, 2023 · 1 comment · Fixed by #9
Closed

Repeated allocation instances #7

baggepinnen opened this issue Oct 9, 2023 · 1 comment · Fixed by #9
Milestone

Comments

@baggepinnen
Copy link
Contributor

baggepinnen commented Oct 9, 2023

I have the following little function I'm using to experiment with

using AllocCheck

send_control(u) = sum(abs2, u) # Dummy control function
calc_control() = 1.0
get_measurement() = [1.0]

function example_loop(data, t_start, y_start, y_old, ydf, Ts, N, r)
    for i = 1:N
        t = time() - t_start
        y = get_measurement()[] - y_start # Subtract initial position for a smoother experience
        yd = (y - y_old) / Ts
        ydf = 0.9*ydf + 0.1*yd
        # r = 45sin(2π*freq*t)
        u = calc_control()
        send_control([u])
        log = [t, y, ydf, u, r(t)]
        data[:, i] .= log
        y_old = y
    end
end

## Generate some example input data
r = t->(2 + 2floor(t/4)^2)
N = 10
data = Matrix{Float64}(undef, 5, N) 
t_start = 1.0
y_start = 0.0
y_old = 0.0
ydf = 0.0
Ts = 1.0

typetuple = typeof.((data, t_start, y_start, y_old, ydf, Ts, N, r))

AllocCheck.check_allocs(example_loop, typetuple, ignore_throw=true)

On Julia v1.10 beta3, I get several repeated AllocInstances for each actual allocation. With ignore_throw = true, I get 18 alloc instances, where at least 4 different sources of allocations are repeated 3 times each (12 instances for 4 real allocations)

Using BenchmarkTools, it appears as if the number of allocations actually happens in each loop iteration is 3 (N=10 loop iterations)

julia> @btime example_loop($data, $t_start, $y_start, $y_old, $ydf, $Ts, $N, $r)
  907.344 ns (30 allocations: 2.19 KiB)

This matches with what I would expect, get_measurement, [u] and log = [t, y, ydf, u, r(t)]

@baggepinnen
Copy link
Contributor Author

baggepinnen commented Oct 9, 2023

Hmm, it seems me workflow using Revise in the terminal was not working as I expected, please ignore this issue for now until I've figured out a better strategy. Sorry for the noise :/


EDIT: I updated the original post

@baggepinnen baggepinnen changed the title Possibly missed allocations Repeated allocation instances Oct 9, 2023
@baggepinnen baggepinnen reopened this Oct 9, 2023
@topolarity topolarity added this to the Public MVP milestone Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants