Skip to content
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

plugin detectident: fixes and improvements #883

Merged
merged 2 commits into from
Mar 17, 2022

Conversation

jgmdev
Copy link
Member

@jgmdev jgmdev commented Mar 15, 2022

Summary

  • Improved performance 67x by not using the tokenizer, this means that now opening files or saving them where indentation is re-detected is much more faster.
  • Improved the algorithm to detect the space size.

When working with the lite-xl-plugins readme I noticed that besides the tokenizer been slow on files with long lines to make things worse, it was loading and saving the file really slow. Started searching for culprits and blaming things that weren't the cause but finally it was the detectindent plugin the culprit of almost all. Here is how slow loading and saving the readme with old indent:

detectindent-tokenizer.mp4

and the non tokenizer version:

detectindent-notokenizer.mp4

How I reached the 67x times figure? well in the past I tried to use the Doc class to generate previews for a symbol references on LSP plugin, but that was painfully slow so used io.open instead, anyways I wrote a benchmark doing that operation and with old detectindent took ~135 seconds, with new detetctindent it takes ~2s.

Besides performance also improved the algorithm to detect the spaces size, so files that where detected like this:

2022-03-15_03:05:05

are now properly detected to:

2022-03-15_03:07:08

Did testing on many files and I would dare say it should have a 99% accuracy 😄 but who knows for real...

That should sum it up!

* Improved performance 67x by not using the tokenizer, this means that
  now opening files or saving them where indentation is re-detected
  is much more faster.
* Improved the algorithm to detect the space size.
@jgmdev jgmdev force-pushed the detectindent-improvements branch from a53d1dc to dcbebef Compare March 16, 2022 01:17
@jgmdev
Copy link
Member Author

jgmdev commented Mar 16, 2022

Fixed bug found by @Guldoman (while we chatted on discord) when dealing with syntaxes that have regex, also fixed some other related mistakes and limit the further ahead look when not finding indentation data to 4 runs also suggested by Guldo.

@jgmdev
Copy link
Member Author

jgmdev commented Mar 17, 2022

Have been working well, merging.

@jgmdev jgmdev merged commit 1f468fc into lite-xl:master Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant