Created
December 18, 2020 14:48
-
-
Save dralletje/ca13addb80783bc1b3c98fdc8fd216dd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
### A Pluto.jl notebook ### | |
# v0.12.17 | |
using Markdown | |
using InteractiveUtils | |
# ╔═╡ 232fcca6-412f-11eb-02d9-9d1fca0a05c7 | |
md""" | |
# Weird Pluto Performance Case | |
`expression_to_execute_in_module` is a piece of code that, apparently, runs slow if running inside a Pluto cell. For some reason it IS quick if you execute it in the Main module, so there is something strange about the new module. | |
""" | |
# ╔═╡ 92c239ec-412e-11eb-1bb2-cbc4d12d358c | |
expression_to_execute_in_module = quote | |
struct in_module_A x end | |
struct in_module_B x end | |
function in_module_thing() | |
local local_time_1 = @elapsed repr([[[[[in_module_A(1)]]]]]) | |
local local_time_2 = @elapsed repr([[[[[in_module_B(1)]]]]]) | |
(local_time_1, local_time_2) | |
end | |
result = @timed in_module_thing() | |
end; | |
# ╔═╡ 9371ecc0-412e-11eb-2747-a73e2e0daa8c | |
md""" | |
### Execute in Main module (fast) | |
""" | |
# ╔═╡ 9385bd40-412e-11eb-2f37-49596b0472cb | |
let | |
Core.eval(Main, expression_to_execute_in_module) | |
end | |
# ╔═╡ 939a4242-412e-11eb-1c4c-f5b528374673 | |
md""" | |
### Execute by though Distributed (faster??) | |
How is this faster? How? | |
EDIT: On binder this is just as fast as **Executing in Main module** | |
""" | |
# ╔═╡ 93cb6a66-412e-11eb-0bbe-71678e1b345b | |
md""" | |
#### Execute in new "sub" module (slow) | |
""" | |
# ╔═╡ 93e03ec8-412e-11eb-1fc9-7f9577be50c7 | |
let | |
SubModule = Module() | |
Core.eval(SubModule, expression_to_execute_in_module) | |
end | |
# ╔═╡ 93f48b26-412e-11eb-2c7d-81749be1d376 | |
md""" | |
### Execute in literal sub module (slow) | |
""" | |
# ╔═╡ 9408fd22-412e-11eb-14b0-5584e66e0d60 | |
module X | |
import ..expression_to_execute_in_module | |
eval(expression_to_execute_in_module) | |
end | |
# ╔═╡ 8843df2c-4131-11eb-1659-1d81c42aba8f | |
X.result | |
# ╔═╡ 941d8b52-412e-11eb-0046-0bd694e9055a | |
md""" | |
## Helpers | |
""" | |
# ╔═╡ 944b0f32-412e-11eb-392e-09d8cd9fae34 | |
import Distributed | |
# ╔═╡ 94602368-412e-11eb-0b67-b17b6562f9da | |
function execute_outside_pluto_but_inside_process(expr) | |
Distributed.remotecall_eval(Main, 1, quote | |
import Distributed | |
Distributed.remotecall_eval( | |
Main, | |
$(Distributed.myid()), | |
$(expression_to_execute_in_module) | |
) | |
end) | |
end | |
# ╔═╡ 93b04600-412e-11eb-0f8b-8d7255f6696c | |
let | |
execute_outside_pluto_but_inside_process(expression_to_execute_in_module) | |
end | |
# ╔═╡ Cell order: | |
# ╟─232fcca6-412f-11eb-02d9-9d1fca0a05c7 | |
# ╠═92c239ec-412e-11eb-1bb2-cbc4d12d358c | |
# ╟─9371ecc0-412e-11eb-2747-a73e2e0daa8c | |
# ╠═9385bd40-412e-11eb-2f37-49596b0472cb | |
# ╟─939a4242-412e-11eb-1c4c-f5b528374673 | |
# ╠═93b04600-412e-11eb-0f8b-8d7255f6696c | |
# ╟─93cb6a66-412e-11eb-0bbe-71678e1b345b | |
# ╠═93e03ec8-412e-11eb-1fc9-7f9577be50c7 | |
# ╟─93f48b26-412e-11eb-2c7d-81749be1d376 | |
# ╟─8843df2c-4131-11eb-1659-1d81c42aba8f | |
# ╠═9408fd22-412e-11eb-14b0-5584e66e0d60 | |
# ╟─941d8b52-412e-11eb-0046-0bd694e9055a | |
# ╠═944b0f32-412e-11eb-392e-09d8cd9fae34 | |
# ╠═94602368-412e-11eb-0b67-b17b6562f9da |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment