While this can of course be worked around by using any sort of external lazy loading, it would be great to have this plugin not require it. Based on profiling with --startuptime, several parts of this plugin are somewhat slow to load. Bear in mind these are from my desktop - my work laptop is much slower.
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
041.349 000.065 000.065: require('image/utils/magic')
041.352 000.215 000.149: require('image/utils/dimensions')
041.391 000.039 000.039: require('image/utils/hash')
041.554 000.162 000.162: require('image/utils/logger')
041.601 000.046 000.046: require('image/utils/math')
041.656 000.055 000.055: require('image/utils/offsets')
041.699 000.043 000.043: require('image/utils/random')
041.768 000.069 000.069: require('image/utils/term')
041.839 000.071 000.071: require('image/utils/tmux')
041.931 000.092 000.092: require('image/utils/window')
041.979 000.047 000.047: require('image/utils/json')
042.004 000.908 000.072: require('image/utils')
054.564 012.107 012.107: require('magick.wand.lib')
055.474 000.173 000.173: require('magick.enum')
055.532 000.414 000.240: require('magick.wand.data')
055.719 000.186 000.186: require('magick.base_image')
055.731 001.015 000.416: require('magick.wand.image')
055.915 000.183 000.183: require('magick.thumb')
056.071 000.155 000.155: require('magick.version')
056.073 013.776 000.316: require('magick.wand')
056.073 013.962 000.186: require('magick')
056.077 014.034 000.072: require('image/processors/magick_rock')
056.359 000.281 000.281: require('image/processors/magick_cli')
056.361 014.356 000.041: require('image/processors')
056.473 000.111 000.111: require('image/report')
056.755 015.911 000.535: require('image')
057.272 000.170 000.170: require('image/backends/kitty/codes')
057.457 000.184 000.184: require('image/backends/kitty/helpers')
060.220 003.392 003.038: require('image/backends/kitty')
060.672 000.283 000.283: require('image/utils/document')
060.676 000.440 000.157: require('image/integrations/typst')
060.773 000.072 000.072: require('image/integrations/neorg')
060.863 000.064 000.064: require('image/integrations/markdown')
060.931 000.065 000.065: require('image/integrations/syslang')
I've cut out unrelated parts of my config. Looking at that, the slow bits are initializing the magick_rock processor (14ms) and the kitty backend (3.4ms). Looks like it's mostly the magick.wand.lib for magick_rock, to be specific.
One simple approach to changing this would be to have api.setup not eagerly load the processor and backend. Rather, it would only check the value to confirm that it's in the set of supported processors/backends. Then the processor itself could be loaded on demand, perhaps by using a Lua metatable if the current API is important to maintain.
While this can of course be worked around by using any sort of external lazy loading, it would be great to have this plugin not require it. Based on profiling with --startuptime, several parts of this plugin are somewhat slow to load. Bear in mind these are from my desktop - my work laptop is much slower.
I've cut out unrelated parts of my config. Looking at that, the slow bits are initializing the magick_rock processor (14ms) and the kitty backend (3.4ms). Looks like it's mostly the magick.wand.lib for magick_rock, to be specific.
One simple approach to changing this would be to have api.setup not eagerly load the processor and backend. Rather, it would only check the value to confirm that it's in the set of supported processors/backends. Then the processor itself could be loaded on demand, perhaps by using a Lua metatable if the current API is important to maintain.