Mochi.DearImGui icon indicating copy to clipboard operation
Mochi.DearImGui copied to clipboard

Add support for ImPlot

Open PathogenDavid opened this issue 2 years ago • 1 comments

https://github.com/epezent/implot

Mostly making this issue to record why certain decisions were made.

Building ImPlot as a separate DLL

I tested building Mochi.DearImGui.Native with ImPlot, here's the sizes in MB:

Platform Config Before After
win-x64 Release 0.88 2.52
linux-x64 Release 1.16 3.67
win-x64 Debug 1.95 4.39
linux-x64 Debug 3.43 11.9

Pretty significant increase across the board. (Linux debug sizes are a little misleading because the debug info is embedded.)

Windows is not the worst ever, but for optional functionality you might not care about it's pretty significant. I suspect significant size increase is mostly due to ImPlot having basically 12 overloads per plot method. Internally it makes very heavy use of inlining so they're not exactly efficient on code space.

I quickly hacked together building ImPlot separately and got these sizes. (The "Sum" column is the ImPlot runtime + the Dear ImGui-only runtime from above. The "Diff" column is the difference between the sum and the after column above.)

Platform Config Size Sum Diff
win-x64 Release 1.64 2.52 +0.00
linux-x64 Release 2.56 3.72 +0.05
win-x64 Debug 2.52 4.47 +0.08
linux-x64 Debug 8.77 12.2 +0.30

The overhead of shipping the DLLs separately is either non-existent or basically negligible.

Verdict: Ship the runtimes separately.

Making a separate repo for Mochi.DearImGui.ImPlot

I think it's best to keep things together because it's important that the native runtimes are both built against the same version of Dear ImGui. We also will always want to release them at the same time for the same reason. In their natural environment, both are statically linked so they neither have a heavy emphasis on ABI stability.

Verdict: Keep everything in one repo.

How to enumerate templated overloads

ImPlot presents an unusual circumstance for Biohazrd: It uses templated methods for most of its functionality, but the templates are all defined for specific types in a C++ file.

In C++ the limits to the methods which can be called is basically enforced at link-time. Calling an overload which does not exist is valid C++, but fails during link. As such there isn't directly a way to enumerate which values of T are valid except by convention.

Need to investigate more. Ideally we'd just parse implot_items.cpp to determine which specializations exist, but I don't think Biohazrd will do it cleanly out of the gate.

PathogenDavid avatar Jun 25 '22 02:06 PathogenDavid