google/vim-maktaba

Deprecate instant/flags.vim

dbarnett opened this issue · 4 comments

Maktaba's instant/ mechanism for executing files immediately has a few drawbacks:

  • Costs overhead on early startup
  • Doesn't interact well with various plugin managers
  • Encourages overuse

It's especially significant if most plugins have an instant/flags.vim file.

We should find another convention for defining flags that doesn't depend on loading them instantly. It could work something like:

  • Flags are defined in whatever standard location for each plugin
  • Maktaba queues up Flag.Set operations until the flag is initialized or read.
  • Flag.Get and any other attempt to access a flag's value will trigger flag initialization.
  • At plugin/ time, all remaining flags are initialized so callbacks and errors trigger.

There'd be some migration pain, and it may not be worth making changes like if there's no measurable performance benefit.

Options for where we'd define flags:

  • plugin/flags.vim (with the understanding that maktaba might manually source it)
  • flags.vim (in the plugin root), always sourced via maktaba
  • addon-info.json (but would need a way to accommodate callbacks)

Note they'd still potentially be expensive if they live in plugin/ where vim would try to detect and source them.

Also note: vimdoc would need to be updated to find flags wherever they end up being defined.

Dug into details and I'm liking plugin/flags.vim. Then any attempt to Set the flag before the flags file is loaded can just queue up the operation and any attempt to Get a flag can ensure flags are loaded and fully resolved first. vim will source plugin/flags.vim in the common case. It'll need a little special handling to ensure it still throws appropriate errors in corner cases (e.g. configuring nonexistent flag names, plugin doesn't have a plugin/flags.vim file that does maktaba#plugin#Enter).

The PLUGIN.flags dict will need some retooling to avoid being able to access it before it's resolved. Probably that public flags dict should be deprecated and replaced with a PLUGIN.Flags helper. That'll power Glaive's autocomplete stuff so it has correct handling, too.

Finally, we'll want to move towards deprecating instant/ support overall and all the overhead that entails. I'm planning to create a temporary maktaba#EnableLegacyInstantFilesSupport() helper. During some transition period, if users have trouble with some maktaba plugin they can use that override to troubleshoot and get a bug filed with plugin maintainers, but that way you only pay the legacy overhead if you're wanting to run legacy plugins that need it.

As a step one we could drop support for other instant files, since flags are going to be a little trickier than the rest. Filed #243 for the general case.

I got a proof of concept in #244 except without the feature of trying to queue up flags operations. In the process I realized that in practice the extra cleverness won't save much overhead, because plugins will tend to look up the magic flags like plugin[commands] before vim gets around to loading the plugin/flags.vim file anyway.