-
Notifications
You must be signed in to change notification settings - Fork 62
Skip loading syntax/pandoc.vim if it's loaded #397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
I noticed that opening markdown files was slow and was trying to optimize the startup. When I run echo "" > foo.md vim --startuptime startup.log foo.md +q I noticed in the `startup.log` that some of the heavier lines in the trace looked redundant. Specifically, I noticed that it was running `syntax/pandoc.vim` multiple times for multiple paths, because Neovim seems to now distribute a `syntax/pandoc.vim` in the distribution's `$VIMRUNTIME` path. What's happening is that the `syntax/pandoc.vim` file loads a bunch of other syntax files to be able to highlight embedded languages in code blocks. That happens every time the files are run, regardless of whether we're already loaded a syntax definition for pandoc once, because there is no `b:current_syntax` guard at the top of the file. Adding the guard in this plugin doesn't actually speed anything up. The speedup only happens when it's made both here and in the `$VIMRUNTIME` distribution files: ❯ rg syntax/pandoc.vim startup.{old,new,both}.log startup.old.log 272.540 025.063 003.008: sourcing /Users/jez/.config/nvim/bundle/vim-pandoc-syntax/syntax/pandoc.vim 296.343 023.082 002.412: sourcing /opt/homebrew/Cellar/neovim/0.10.4_1/share/nvim/runtime/syntax/pandoc.vim 297.630 000.008 000.008: sourcing /Users/jez/.config/nvim/after/syntax/pandoc.vim 361.296 024.097 002.412: sourcing /Users/jez/.config/nvim/bundle/vim-pandoc-syntax/syntax/pandoc.vim 385.468 023.663 002.443: sourcing /opt/homebrew/Cellar/neovim/0.10.4_1/share/nvim/runtime/syntax/pandoc.vim 385.853 000.007 000.007: sourcing /Users/jez/.config/nvim/after/syntax/pandoc.vim 146.991 028.210 003.364: sourcing /Users/jez/.config/nvim/bundle/vim-pandoc-syntax/syntax/pandoc.vim 175.621 027.840 003.237: sourcing /opt/homebrew/Cellar/neovim/0.10.4_1/share/nvim/runtime/syntax/pandoc.vim 176.466 000.011 000.011: sourcing /Users/jez/.config/nvim/after/syntax/pandoc.vim 241.812 025.036 002.764: sourcing /Users/jez/.config/nvim/bundle/vim-pandoc-syntax/syntax/pandoc.vim 269.082 026.633 003.041: sourcing /opt/homebrew/Cellar/neovim/0.10.4_1/share/nvim/runtime/syntax/pandoc.vim 269.506 000.009 000.009: sourcing /Users/jez/.config/nvim/after/syntax/pandoc.vim startup.new.log 160.321 024.925 003.534: sourcing /Users/jez/.config/nvim/bundle/vim-pandoc-syntax/syntax/pandoc.vim 184.483 022.947 002.397: sourcing /opt/homebrew/Cellar/neovim/0.10.4_1/share/nvim/runtime/syntax/pandoc.vim 186.524 000.008 000.008: sourcing /Users/jez/.config/nvim/after/syntax/pandoc.vim 251.792 022.884 002.144: sourcing /Users/jez/.config/nvim/bundle/vim-pandoc-syntax/syntax/pandoc.vim 275.302 023.001 002.316: sourcing /opt/homebrew/Cellar/neovim/0.10.4_1/share/nvim/runtime/syntax/pandoc.vim 275.634 000.007 000.007: sourcing /Users/jez/.config/nvim/after/syntax/pandoc.vim 152.428 025.671 003.712: sourcing /Users/jez/.config/nvim/bundle/vim-pandoc-syntax/syntax/pandoc.vim 176.968 023.461 002.483: sourcing /opt/homebrew/Cellar/neovim/0.10.4_1/share/nvim/runtime/syntax/pandoc.vim 179.083 000.008 000.008: sourcing /Users/jez/.config/nvim/after/syntax/pandoc.vim 243.327 023.138 002.234: sourcing /Users/jez/.config/nvim/bundle/vim-pandoc-syntax/syntax/pandoc.vim 266.798 022.957 002.340: sourcing /opt/homebrew/Cellar/neovim/0.10.4_1/share/nvim/runtime/syntax/pandoc.vim 267.128 000.007 000.007: sourcing /Users/jez/.config/nvim/after/syntax/pandoc.vim startup.both.log 175.965 027.418 003.803: sourcing /Users/jez/.config/nvim/bundle/vim-pandoc-syntax/syntax/pandoc.vim 177.070 000.007 000.007: sourcing /opt/homebrew/Cellar/neovim/0.10.4_1/share/nvim/runtime/syntax/pandoc.vim 178.088 000.009 000.009: sourcing /Users/jez/.config/nvim/after/syntax/pandoc.vim 242.550 024.351 002.335: sourcing /Users/jez/.config/nvim/bundle/vim-pandoc-syntax/syntax/pandoc.vim 243.092 000.006 000.006: sourcing /opt/homebrew/Cellar/neovim/0.10.4_1/share/nvim/runtime/syntax/pandoc.vim 243.447 000.007 000.007: sourcing /Users/jez/.config/nvim/after/syntax/pandoc.vim 147.441 026.421 003.213: sourcing /Users/jez/.config/nvim/bundle/vim-pandoc-syntax/syntax/pandoc.vim 148.317 000.008 000.008: sourcing /opt/homebrew/Cellar/neovim/0.10.4_1/share/nvim/runtime/syntax/pandoc.vim 149.163 000.010 000.010: sourcing /Users/jez/.config/nvim/after/syntax/pandoc.vim 219.914 026.378 002.627: sourcing /Users/jez/.config/nvim/bundle/vim-pandoc-syntax/syntax/pandoc.vim 220.423 000.006 000.006: sourcing /opt/homebrew/Cellar/neovim/0.10.4_1/share/nvim/runtime/syntax/pandoc.vim 220.797 000.010 000.010: sourcing /Users/jez/.config/nvim/after/syntax/pandoc.vim ❯ wc -l startup.{old,new,both}.log 624 startup.old.log 624 startup.new.log 520 startup.both.log What we see happening in these files is that **only** adding the `b:current_syntax` guard in this plugin only saves ~2ms (269ms → 267ms). But once we add it to both the plugin and the distribution, then it completely skips running the `syntax/pandoc.vim` the second time, which also skips loading all the embedded syntax files (represented by a drop in the number of entries in the startup.log files from 624 lines to 520 lines). This drops the total load time from 269ms → 220ms. For the time being, I have manually edited my `$VIMRUNTIME/syntax/pandoc.vim` file to also include these changes, but it will be a subsequent priority to make sure that these plugin changes get pulled into the distribution.
Note: the linter failure on this change is an infrastructure problem, not a problem with this PR. See #398. |
jez
added a commit
to jez/vim-pandoc-syntax
that referenced
this pull request
Apr 17, 2025
This was a bad merge that resulted from vim-pandoc#393 being opened before vim-pandoc#397 but landing after. If we override the `&cpo` option and then `finish`, it will never get set back to the saved cpo. Instead, let's just only do the `set` if we're sure we're not going to early exit.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed that opening markdown files was slow and was trying to
optimize the startup.
When I run
I noticed in the
startup.log
that some of the heavier lines in thetrace looked redundant. Specifically, I noticed that it was running
syntax/pandoc.vim
multiple times for multiple paths, because Neovimseems to now distribute a
syntax/pandoc.vim
in the distribution's$VIMRUNTIME
path.What's happening is that the
syntax/pandoc.vim
file loads a bunch ofother syntax files to be able to highlight embedded languages in code
blocks.
That happens every time the files are run, regardless of whether we're
already loaded a syntax definition for pandoc once, because there is no
b:current_syntax
guard at the top of the file.Adding the guard in this plugin doesn't actually speed anything up. The
speedup only happens when it's made both here and in the
$VIMRUNTIME
distribution files:
What we see happening in these files is that only adding the
b:current_syntax
guard in this plugin only saves ~2ms (269ms → 267ms).But once we add it to both the plugin and the distribution, then it
completely skips running the
syntax/pandoc.vim
the second time, whichalso skips loading all the embedded syntax files (represented by a drop
in the number of entries in the startup.log files from 624 lines to 520
lines). This drops the total load time from 269ms → 220ms.
For the time being, I have manually edited my
$VIMRUNTIME/syntax/pandoc.vim
file to also include these changes, butit will be a subsequent priority to make sure that these plugin changes
get pulled into the distribution.