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

Make use of Base.donotdelete if available #275

Merged
merged 1 commit into from
Feb 8, 2022
Merged

Conversation

Keno
Copy link
Member

@Keno Keno commented Feb 4, 2022

@vchuravy
Copy link
Member

vchuravy commented Feb 4, 2022

I am not sure that running this unconditionally is the best idea. One of the stated intentions for BenchmarkTools has always been that it will execute the JuliaCode as is, to match the actual behavior as close as possible.

I see the utility for BaseBenchmarks, but maybe it should change the definition to include dcebarrier(sin(x))?

@Keno
Copy link
Member Author

Keno commented Feb 4, 2022

I would think that most benchmarks don't actually have any side-effects, so as the compiler gets better I think we'll be deleting them more and more. I think people would expect that the return value from their benchmarks would get preserved (as it would if you just run it at the REPL, because then it gets assigned to ans).

@KristofferC
Copy link
Contributor

One of the stated intentions for BenchmarkTools has always been that it will execute the JuliaCode as is, to match the actual behavior as close as possible

A better intention seems to me to have BenchmarkTools be as useful as possible. And when it optimizes away the whole benchmark, it is not being useful. The hoops you have to jump through now with interpolating Ref etc just to get a useful answer is annoying. This seems like an improvement.

@Keno Keno changed the title Make use of Base.dcebarrier if available Make use of Base.donotdelete if available Feb 8, 2022
@Keno
Copy link
Member Author

Keno commented Feb 8, 2022

Base is ready to merge, so let's get this in, so we can do the Base nanosoldier run.

@vchuravy vchuravy merged commit ad8f1bc into master Feb 8, 2022
@vchuravy vchuravy deleted the kf/dcebarrier branch February 8, 2022 02:28
@giordano
Copy link
Member

After this PR @btime doesn't return the output of the operation anymore:

julia> using BenchmarkTools; @btime 1 + 2
  1.413 ns (0 allocations: 0 bytes)

julia>

@Keno
Copy link
Member Author

Keno commented Feb 12, 2022

Ah, sorry. An earlier version of the built-in returned it's result. I'm not at a computer right now, but just put in a let statement or something that properly returns the result.

@giordano
Copy link
Member

You mean like this:

--- a/src/execution.jl
+++ b/src/execution.jl
@@ -480,7 +480,10 @@ function generate_benchmark_definition(eval_module, out_vars, setup_vars, quote_
         core_body = :($(core); $(returns))
     end
     if isdefined(Base, :donotdelete)
-        invocation = :(Base.donotdelete($invocation))
+        invocation = :(let x = $invocation
+                           Base.donotdelete(x)
+                           x
+                       end)
     end
     return Core.eval(eval_module, quote
         @noinline $(signature_def) = begin $(core_body) end

? I'm not entirely sure whether x needs to be inside donotdelete or not (I think so because that should be the point of this function).

@Keno
Copy link
Member Author

Keno commented Feb 12, 2022

Yes, that patch would work

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 this pull request may close these issues.

4 participants