Skip to content

Commit

Permalink
Merge pull request #165 from JuliaImGui/precompile
Browse files Browse the repository at this point in the history
Add precompilation workloads and bump version
  • Loading branch information
JamesWrigley authored Feb 16, 2025
2 parents b6ca5b3 + 56e09b7 commit 1b33891
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 46 deletions.
35 changes: 0 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,6 @@ permissions:
contents: read

jobs:
loading:
name: Loading only - Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.9'
- '1'
- 'nightly'
os:
- macOS-latest
- windows-latest
arch:
- x64
- x86
exclude:
- os: macOS-latest
arch: x86
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v2

# We add ModernGL and GLFW so that the backend extensions will be loaded too
- run: |
julia --project=. -e '
using Pkg
Pkg.add(["ModernGL", "GLFW"])
import CImGui, ModernGL, GLFW
'
tests:
name: Tests - Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
Expand Down
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
name = "CImGui"
uuid = "5d785b6c-b76f-510e-a07c-3070796c7e87"
authors = ["Yupei Qi <[email protected]>"]
version = "5.0.0"
version = "5.0.1"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
CImGuiPack_jll = "333409e9-af72-5310-9767-d6ad21a76a05"
CSyntax = "ea656a56-6ca6-5dda-bba5-7b6963a5f74c"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

Expand All @@ -30,6 +31,7 @@ DocStringExtensions = "0.9.3"
GLFW = "3"
GLMakie = "0.10.6, 0.11"
ModernGL = "1"
PrecompileTools = "1.2.1"
Printf = "1"
Statistics = "1"
julia = "1.9"
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ makedocs(;
canonical="https://juliaimgui.github.io/CImGui.jl",
assets=String[],
size_threshold=2_000_000,
size_threshold_warn=1_500_000
size_threshold_warn=2_000_000
),
pages=["index.md", "api.md", "backends.md", "makie.md", "changelog.md"]
)
Expand Down
13 changes: 13 additions & 0 deletions docs/src/_changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ CurrentModule = CImGui
This documents notable changes in CImGui.jl. The format is based on [Keep a
Changelog](https://keepachangelog.com).

## [v5.0.1] - 2025-02-17

### Changed
- Added precompilation workloads for the GLFW/OpenGL backend and the Makie
extension ([#165]). This reduced the execution time of some tests involving the
GLFW/OpenGL backend from ~2.5s to ~1.8s, and the execution time of the Makie
integration tests from ~15s to ~5s.

It is possible that the workloads are not portable: if you get a
precompilation error please report it as a bug with the error message. The
precompilation workloads can be disabled completely [using the PrecompileTools
preferences](https://julialang.github.io/PrecompileTools.jl/stable/#Package-developers:-reducing-the-cost-of-precompilation-during-development).

## [v5.0.0] - 2025-02-05

### Changed
Expand Down
18 changes: 17 additions & 1 deletion ext/GlfwOpenGLBackend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import CImGui.lib as lib
import GLFW
import ModernGL as GL

using PrecompileTools: @compile_workload


# Helper function to get the GLSL version
function get_glsl_version(gl_version)
Expand Down Expand Up @@ -144,7 +146,7 @@ function renderloop(ui, ctx::Ptr{lib.ImGuiContext}, ::Val{:GlfwOpenGL3};
yield()
end
catch e
@error "Error in CImGui $(ig._backend[]) renderloop!" exception=(e, catch_backtrace())
@error "Error in CImGui $(ig._backend) renderloop!" exception=(e, catch_backtrace())
finally
for func in vcat(ig._exit_handlers, isnothing(on_exit) ? [] : [on_exit])
try
Expand Down Expand Up @@ -194,4 +196,18 @@ function ig._render(args...; spawn::Union{Bool, Integer, Symbol}=1, wait::Bool=t
return wait ? Base.wait(monitor_task) : monitor_task
end

@compile_workload begin
ctx = ig.CreateContext()
ig.set_backend(:GlfwOpenGL3)
ig.render(ctx; window_title="CImGui precompile workload") do
ig.Begin("Foo")
ig.Text("foo")
ig.End()

return :imgui_exit_loop
end

ig._backend = nothing
end

end
24 changes: 24 additions & 0 deletions ext/MakieIntegration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import GLFW
import GLMakie
import GLMakie.Makie as Makie

using PrecompileTools: @setup_workload, @compile_workload


# Represents a single Figure to be shown as an ImGui image texture
struct ImMakieWindow
glfw_window::GLFW.Window # Only needed for supporting GLMakie requirements
Expand Down Expand Up @@ -269,4 +272,25 @@ function __init__()
Makie.set_theme!(theme_imgui())
end

@setup_workload begin
f = GLMakie.Figure()
GLMakie.lines(f[1, 1], rand(10))

@compile_workload begin
ig.set_backend(:GlfwOpenGL3)
ctx = ig.CreateContext()

ig.render(ctx; window_title="CImGui/Makie precompilation workload", opengl_version=v"3.3") do
ig.Begin("Foo")
ig.MakieFigure("plot", f)
ig.End()

return :imgui_exit_loop
end

destroy_context()
ig._backend = nothing
end
end

end
16 changes: 8 additions & 8 deletions src/CImGui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function _update_image_texture end
function _destroy_image_texture end
function _current_window end

const _backend = Ref{Symbol}()
_backend::Union{Symbol, Nothing} = nothing

"""
set_backend(backend::Symbol)
Expand All @@ -156,11 +156,11 @@ function set_backend(backend::Symbol)
throw(ArgumentError("Unrecognized backend: $(backend)"))
end

global _backend[] = backend
global _backend = backend
end

function _check_backend()
if !isassigned(_backend)
if isnothing(_backend)
error("You must call `CImGui.set_backend()` to the backend you want before calling this function, e.g. `CImGui.set_backend(:GlfwOpenGL3)` for the GLFW/OpenGL3 backend.")
end
end
Expand Down Expand Up @@ -227,27 +227,27 @@ Keyword arguments:
"""
function render(args...; kwargs...)
_check_backend()
_render(args..., Val(_backend[]); kwargs...)
_render(args..., Val(_backend); kwargs...)
end

function current_window()
_check_backend()
_current_window(Val(_backend[]))
_current_window(Val(_backend))
end

function create_image_texture(args...; kwargs...)
_check_backend()
_create_image_texture(Val(_backend[]), args...; kwargs...)
_create_image_texture(Val(_backend), args...; kwargs...)
end

function update_image_texture(args...; kwargs...)
_check_backend()
_update_image_texture(Val(_backend[]), args...; kwargs...)
_update_image_texture(Val(_backend), args...; kwargs...)
end

function destroy_image_texture(args...; kwargs...)
_check_backend()
_destroy_image_texture(Val(_backend[]), args...; kwargs...)
_destroy_image_texture(Val(_backend), args...; kwargs...)
end

## Test engine
Expand Down

2 comments on commit 1b33891

@JamesWrigley
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/125241

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v5.0.1 -m "<description of version>" 1b338915bbb5e4956916886b1dcc5e1044dd08d2
git push origin v5.0.1

Please sign in to comment.