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

Autocomplete speedup vol. 2 - finishing #680

Merged
merged 48 commits into from
Nov 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
2d91ee8
speedup autocomplete with ReadableIndex::getDefinitionsForNamespace
nicolasmure Aug 6, 2017
b7c7128
update tests
nicolasmure Aug 6, 2017
6d725a2
speedup static access autocomplete
nicolasmure Aug 6, 2017
18f2f4c
cleanup
nicolasmure Aug 6, 2017
17602aa
globalDefinitions cache to speedup autocomplete
nicolasmure Aug 6, 2017
6d30035
also remove empty namespace index
nicolasmure Aug 8, 2017
ca0caf1
store definitions under the namespaceDefinitions cache key directly
nicolasmure Aug 9, 2017
8768b69
use Generators to get definitions without wasting memory
nicolasmure Aug 9, 2017
8801edb
also yield URIs to save memory
nicolasmure Aug 9, 2017
6a41a7f
add example of indexed definitions
nicolasmure Aug 10, 2017
6a36828
avoid useless array
nicolasmure Aug 10, 2017
e34d8e1
use of null coalescing operator
nicolasmure Aug 10, 2017
14f840b
use correct terminology
nicolasmure Oct 5, 2017
e9fd572
consider the merge of #511
nicolasmure Nov 13, 2017
d1f85f1
use tree representation index
nicolasmure Nov 13, 2017
188a5df
fix definitions storage collision (member / non member)
nicolasmure Nov 14, 2017
cacde1e
use a single array to store definitions
nicolasmure Nov 14, 2017
e162d94
cleanup
nicolasmure Nov 14, 2017
7437d30
Fix formatting
felixfbecker Nov 15, 2017
b118c77
Correct some docblocks
felixfbecker Nov 15, 2017
b3f30f3
cache is backward compatible
nicolasmure Nov 15, 2017
7511e25
Merge branch 'master' into feature/autocomplete-speedup
felixfbecker Nov 15, 2017
fcdf791
use string concatenation instead of sprintf
nicolasmure Nov 16, 2017
3bda390
Merge branch 'master' into feature/autocomplete-speedup
felixfbecker Nov 19, 2017
b03950c
Cleanup
felixfbecker Nov 18, 2017
97ec127
fix definition removal
nicolasmure Nov 19, 2017
48bbbb5
differenciate member and non member definitions
nicolasmure Nov 19, 2017
67dd980
Merge branch 'master' into feature/autocomplete-speedup
felixfbecker Nov 19, 2017
91ca99a
Revert "differenciate member and non member definitions"
felixfbecker Nov 23, 2017
fa67f84
perf: get direct children
felixfbecker Nov 23, 2017
81c40f2
chore: add completion benchmark
felixfbecker Nov 23, 2017
8617948
Merge remote-tracking branch 'origin/master' into autocomplet-speedup
Declspeck Feb 3, 2018
439cebe
fix(tests): fix require in parsing.php benchmark after file move
Declspeck Feb 3, 2018
e589f9e
refactor(completion): make completion of global symbols use Index mor…
Declspeck Feb 3, 2018
6858bd3
tests(completion): add completion of new| ParameterBag to completion …
Declspeck Feb 3, 2018
d6b4e79
feat(completion): complete for used namespaces
Declspeck Feb 9, 2018
98ac9ff
Merge branch 'master' into autocomplet-speedup
Declspeck Feb 9, 2018
d1933b8
refactor(completion): rewrite global name completion with generators
Declspeck Feb 15, 2018
0bc5b81
fix(completion): Return type hint
Declspeck Feb 15, 2018
334683a
Merge branch 'master' into autocomplet-speedup
Declspeck Mar 1, 2018
5921fd3
Address feedback
Declspeck Mar 10, 2018
3d5f0ca
Merge branch 'master' into autocomplet-speedup
Declspeck Mar 10, 2018
118115f
Merge branch 'master' into autocomplet-speedup
MichaelBelgium Nov 6, 2018
b625b0e
Rename CompletionItem to CompletionItemFactory
MichaelBelgium Nov 10, 2018
c5ec18f
squash! fix benchmark protocol namespace reference
felixfbecker Nov 10, 2018
0a48df9
chore: disable XDebug in benchmarks
felixfbecker Nov 11, 2018
2a2fa1c
chore: log progress in parsing benchmark
felixfbecker Nov 11, 2018
52179d0
fix: don't save classes without name to index
felixfbecker Nov 11, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
89 changes: 89 additions & 0 deletions benchmarks/completion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace LanguageServer\Tests;
require __DIR__ . '/../vendor/autoload.php';

use Composer\XdebugHandler\XdebugHandler;
use Exception;
use LanguageServer\CompletionProvider;
use LanguageServer\DefinitionResolver;
use LanguageServer\Index\Index;
use LanguageServer\PhpDocument;
use LanguageServer\StderrLogger;
use LanguageServerProtocol\Position;
use Microsoft\PhpParser;
use phpDocumentor\Reflection\DocBlockFactory;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

$logger = new StderrLogger();
$xdebugHandler = new XdebugHandler('PHPLS');
$xdebugHandler->setLogger($logger);
$xdebugHandler->check();
unset($xdebugHandler);

$totalSize = 0;

$framework = "symfony";

$iterator = new RecursiveDirectoryIterator(__DIR__ . "/../validation/frameworks/$framework");
$testProviderArray = array();

foreach (new RecursiveIteratorIterator($iterator) as $file) {
if (strpos((string)$file, ".php") !== false) {
$totalSize += $file->getSize();
$testProviderArray[] = $file->getRealPath();
}
}

if (count($testProviderArray) === 0) {
throw new Exception("ERROR: Validation testsuite frameworks not found - run `git submodule update --init --recursive` to download.");
}

$index = new Index;
$definitionResolver = new DefinitionResolver($index);
$completionProvider = new CompletionProvider($definitionResolver, $index);
$docBlockFactory = DocBlockFactory::createInstance();
$completionFile = realpath(__DIR__ . '/../validation/frameworks/symfony/src/Symfony/Component/HttpFoundation/Request.php');
$parser = new PhpParser\Parser();
$completionDocument = null;

echo "Indexing $framework" . PHP_EOL;

foreach ($testProviderArray as $idx => $testCaseFile) {
if (filesize($testCaseFile) > 100000) {
continue;
}
if ($idx % 100 === 0) {
echo $idx . '/' . count($testProviderArray) . PHP_EOL;
}

$fileContents = file_get_contents($testCaseFile);

try {
$d = new PhpDocument($testCaseFile, $fileContents, $index, $parser, $docBlockFactory, $definitionResolver);
if ($testCaseFile === $completionFile) {
$completionDocument = $d;
}
} catch (\Throwable $e) {
echo $e->getMessage() . PHP_EOL;
continue;
}
}

echo "Getting completion". PHP_EOL;

// Completion in $this->|request = new ParameterBag($request);
$start = microtime(true);
$list = $completionProvider->provideCompletion($completionDocument, new Position(274, 15));
$end = microtime(true);
echo 'Time ($this->|): ' . ($end - $start) . 's' . PHP_EOL;
echo count($list->items) . ' completion items' . PHP_EOL;

// Completion in $this->request = new| ParameterBag($request);
// (this only finds ParameterBag though.)
$start = microtime(true);
$list = $completionProvider->provideCompletion($completionDocument, new Position(274, 28));
$end = microtime(true);
echo 'Time (new|): ' . ($end - $start) . 's' . PHP_EOL;
echo count($list->items) . ' completion items' . PHP_EOL;
18 changes: 13 additions & 5 deletions Performance.php → benchmarks/parsing.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
<?php

namespace LanguageServer\Tests;
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/../vendor/autoload.php';

use Composer\XdebugHandler\XdebugHandler;
use Exception;
use LanguageServer\DefinitionResolver;
use LanguageServer\Index\Index;
use LanguageServer\PhpDocument;
use LanguageServer\DefinitionResolver;
use LanguageServer\StderrLogger;
use Microsoft\PhpParser;
use phpDocumentor\Reflection\DocBlockFactory;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

$logger = new StderrLogger();
$xdebugHandler = new XdebugHandler('PHPLS');
$xdebugHandler->setLogger($logger);
$xdebugHandler->check();
unset($xdebugHandler);

$totalSize = 0;

$frameworks = ["drupal", "wordpress", "php-language-server", "tolerant-php-parser", "math-php", "symfony", "codeigniter", "cakephp"];

foreach($frameworks as $framework) {
$iterator = new RecursiveDirectoryIterator(__DIR__ . "/validation/frameworks/$framework");
$iterator = new RecursiveDirectoryIterator(__DIR__ . "/../validation/frameworks/$framework");
$testProviderArray = array();

foreach (new RecursiveIteratorIterator($iterator) as $file) {
Expand All @@ -37,8 +45,8 @@
if (filesize($testCaseFile) > 10000) {
continue;
}
if ($idx % 1000 === 0) {
echo "$idx\n";
if ($idx % 500 === 0) {
echo $idx . '/' . count($testProviderArray) . PHP_EOL;
}

$fileContents = file_get_contents($testCaseFile);
Expand Down
10 changes: 10 additions & 0 deletions fixtures/completion/used_namespace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Whatever;

use TestNamespace\InnerNamespace as AliasNamespace;

class IDontShowUpInCompletion {}

AliasNamespace\I;
AliasNamespace\;
5 changes: 5 additions & 0 deletions fixtures/symbols.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,8 @@ class Example {
public function __construct() {}
public function __destruct() {}
}

namespace TestNamespace\InnerNamespace;

class InnerClass {
}