Skip to content

Commit

Permalink
[Fix #1147] Introduce a faster indexing method
Browse files Browse the repository at this point in the history
The turbo-alien indexing method optimizes to the limit the speed
of the alien indexing method.  This means that Projectile will
not do any processing of the files returned by the external
commands and you're going to get the maximum performance
possible.  This behaviour makes a lot of sense for most people,
as they'd typically be putting ignores in their VCS config and
won't care about any additional ignores/unignores/sorting that
Projectile might also provide.
  • Loading branch information
bbatsov committed Sep 29, 2018
1 parent e6a6b3d commit e3007ae
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* New interactive command `projectile-run-ielm`.
* Add [crystal](https://crystal-lang.org) project type.
* [#850](https://github.com/bbatsov/projectile/issues/850): Make it possible to prompt for a project, when you're not in a project, instead of raising an error. (see `projectile-require-project-root`).
* [#1147](https://github.com/bbatsov/projectile/issues/1147): Introduce a faster indexing method - `turbo-alien`.

### Changes

Expand Down
41 changes: 28 additions & 13 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@ want to fine-tune to make Projectile fit your workflow better.

## Project indexing method

Projectile has two modes of operation - one is portable and is
implemented in Emacs Lisp (therefore it's *native* to Emacs and is known
as the `native indexing method`) and the other relies on external
commands like `find`, `git`, etc to obtain the list of files in a
project.

Projectile has three modes of operation - one is portable and is
implemented in Emacs Lisp (therefore it's *native* to Emacs and is
known as the `native indexing method`) and the other two (`alien` and
`turbo-alien`) rely on external commands like `find`, `git`, etc to
obtain the list of files in a project.

The `turbo-alien` indexing method optimizes to the limit the speed of
the `alien` indexing method. This means that Projectile will not do
any processing of the files returned by the external commands and
you're going to get the maximum performance possible. This behaviour
makes a lot of sense for most people, as they'd typically be putting
ignores in their VCS config (e.g. `.gitignore`) and won't care about
any additional ignores/unignores/sorting that Projectile might also

This comment has been minimized.

Copy link
@dgutov

dgutov Nov 20, 2018

Contributor

TBH, I've been thinking about this problem a while, and I disagree with this solution (if it's considered final).

In the projects I'm working on, we have both files checked into Git but ones that I want to see ignored for navigation (e.g. VCR cassettes), as well as vice versa (some config files, e.g. settings.yml, when the version checked into Git is called settings.sample.yml).

I think we can combine the ignore lists somehow and pass the result to Git using --exclude-from. I've been toying with this approach for the built-in project.el backend, albeit very slowly.

This comment has been minimized.

Copy link
@bbatsov

bbatsov Dec 5, 2018

Author Owner

Yeah, that's a reasonable idea. I also toyed with a similar idea (and also considered using ignore patterns just as in .gitignore for Projectile), but haven't made much progress on this front.

I do think there's benefit to having a very fast and very simple indexing backend in conjunction with something that's more sophisticated, but if we can make it very fast and somewhat sophisticated that would be even nicer. Please, file some ticket about this, so it won't slip through the cracks. Lately it has been very busy on my end, and I'm not sure when I'll be able to revisit my work on Projectile. I'll try to at least cut some release with all the recent changes, though.

provide.

!!! Info

Since the `native` indexing mode is much slower, by default the `alien`
method is used on all operating systems except Windows.
By default the `turbo-alien` method is used on all operating systems except Windows.
Prior to Projectile 1.1 `alien` used to be the default.

To force the
use of native indexing in all operating systems:
Expand All @@ -25,16 +33,23 @@ use of native indexing in all operating systems:
(setq projectile-indexing-method 'native)
```

To force the use of alien indexing in all operating system:
To force the use of alien indexing in all operating systems:

```el
(setq projectile-indexing-method 'alien)
```

This can speed up Projectile in Windows significantly. The
disadvantage of this method is that it's not well supported on Windows
systems, as it requires setting up some Unix utilities there. If
there's problem, you can always use native indexing mode.
To force the use of turbo alien indexing in all operating systems:

```el
(setq projectile-indexing-method 'turbo-alien)
```

This can speed up Projectile in Windows significantly (especially on
big projects). The disadvantage of this method is that it's not well
supported on Windows systems, as it requires setting up some Unix
utilities there. If there's problem, you can always use `native`
indexing mode.

## Caching

Expand Down
24 changes: 18 additions & 6 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
:link '(url-link :tag "Online Manual" "https://docs.projectile.mx/")
:link '(emacs-commentary-link :tag "Commentary" "projectile"))

(defcustom projectile-indexing-method (if (eq system-type 'windows-nt) 'native 'alien)
(defcustom projectile-indexing-method (if (eq system-type 'windows-nt) 'native 'turbo-alien)
"Specifies the indexing method used by Projectile.
There are two indexing methods - native and alien.
Expand All @@ -93,12 +93,22 @@ The alien indexing method uses external tools (e.g. git, find,
etc) to speed up the indexing process. The disadvantage of this
method is that it's not well supported on Windows systems.
By default alien indexing is the default on all operating
The turbo-alien indexing method optimizes to the limit the speed
of the alien indexing method. This means that Projectile will
not do any processing of the files returned by the external
commands and you're going to get the maximum performance
possible. This behaviour makes a lot of sense for most people,
as they'd typically be putting ignores in their VCS config and
won't care about any additional ignores/unignores/sorting that
Projectile might also provide.
By default turbo-alien indexing is the default on all operating
systems, except Windows."
:group 'projectile
:type '(radio
(const :tag "Native" native)
(const :tag "Alien" alien)))
(const :tag "Alien" alien)
(const :tag "Turbo Alien" turbo-alien)))

(defcustom projectile-enable-caching (eq projectile-indexing-method 'native)
"When t enables project files caching.
Expand Down Expand Up @@ -1057,10 +1067,12 @@ Files are returned as relative paths to the project ROOT."
(gethash directory projectile-projects-cache))))
;; cache disabled or cache miss
(or files-list
(if (eq projectile-indexing-method 'native)
(projectile-dir-files-native root directory)
(pcase projectile-indexing-method
('native (projectile-dir-files-native root directory))
;; use external tools to get the project files
(projectile-adjust-files (projectile-dir-files-external directory))))))
('alien (projectile-adjust-files (projectile-dir-files-external directory)))
('turbo-alien (projectile-dir-files-external directory))
(_ (user-error "Unsupported indexing method `%S'" projectile-indexing-method))))))

(defun projectile-dir-files-native (root directory)
"Get the files for ROOT under DIRECTORY using just Emacs Lisp."
Expand Down

2 comments on commit e3007ae

@citypilgrim
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any updates on this? Has it been merged into master?

@bbatsov
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.