This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 244678 - CodeCompletion took 11854 ms.
Summary: CodeCompletion took 11854 ms.
Status: RESOLVED FIXED
Alias: None
Product: web
Classification: Unclassified
Component: CSS Editor (show other bugs)
Version: 8.0
Hardware: All All
: P1 normal (vote)
Assignee: Petr Pisl
URL:
Keywords: PERFORMANCE
Depends on: 244952
Blocks:
  Show dependency tree
 
Reported: 2014-05-23 08:31 UTC by peppertech
Modified: 2014-06-25 02:31 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 209884


Attachments
nps snapshot (98.61 KB, application/nps)
2014-05-23 08:31 UTC, peppertech
Details

Note You need to log in before you can comment on or make changes to this bug.
Description peppertech 2014-05-23 08:31:26 UTC
This issue was reported manually by pjiricka.
It already has 1 duplicates 


Build: NetBeans IDE Dev (Build javascript2-frameworks-48-on-20140515)
VM: Java HotSpot(TM) 64-Bit Server VM, 25.5-b02, Java(TM) SE Runtime Environment, 1.8.0_05-b13
OS: Windows 7

User Comments:
peppertech: This is displayed when trying to do CSS style code completion with a the default minified version of JET's Alta stylesheet.  It seems like it takes longer than 11 seconds, but I'll trust the IDE to tell me what the real time is.



Maximum slowness yet reported was 11854 ms, average is 11854
Comment 1 peppertech 2014-05-23 08:31:29 UTC
Created attachment 147398 [details]
nps snapshot
Comment 2 Petr Jiricka 2014-05-23 08:33:00 UTC
Code completion takes a really long time -> P1.
Comment 3 Petr Jiricka 2014-06-05 13:18:58 UTC
Petr P says he's been looking into this issue briefly, so he may have some insights.
Comment 4 Petr Pisl 2014-06-06 15:17:20 UTC
So after better evaluation the problem is not that the project contains JET's Alta style. The problem is that the project contains many files, that can contribute to the css model and the algorithm for finding all CSS models is expensive.

Basically the most invoked operation in this is IndexResult.getFile(), which invoke URLMapper.findFileObject(url), when the result doesn't have cached the file yet. It's not very expensive, but is asking the file systems to find the file and whether the file exists (this query can be expensive on some NTFS file system). But I need to mentioned that this is not important. The important is that is invoked so many times.

I have played with JetDemoApp from Tailwind and this is called 368 724x for one code completion in the index.html file and these calls take about 17 seconds on my machine in debug mode(slower, than in the normal mode). So now there is a question, why it's called so many times.

The index.html file links (through the <link> tag) 9 files. All these files are included to the dependency graph, even if a file is an icon or an image. Before obtaining CssModels is build a list of all files that can participate on the css model. So to the dependency list are included files that are mentioned in the index.html and recursively all files mentioned in these files etc. As a result the dependency list has 232 files, including .png, .ttf, .jpg, .etc files, that doesn't have to be there and they cannot participate on the css model. I think eliminating these files from the dependency graph can improve the performance. Probably it will not be very significant improvement, but it can save next processing.

So now we have 232 files that are obtained from dependency graph and the algorithm is collecting css model for every file from this list. The model is obtained from the index through a prefix query, but the prefix is empty. It means that it returns 450 results from index in our case, but only one is the right one. To find the right one, the algorithm goes through these 450 results and checks whether the indexed result is from the file, for which the css model is look for. And this is the moment, why the IndexResult.getFile() is called so many times. In the worth case it's 232 x 450 = 104 400. But obtaining the css models for edited file is processed at least twice, often 4 times.(from different places).

Possible fix would be to ask the index directly for the file and not use the prefix query. I need to discuss this with Tomas Z. how to do this. Other possible solution will be to cached the css models from index for the files.

Also eliminating files like png, jpg, ttf etc. from dependency graph can help, because queries to the index will not be done for such files.
Comment 5 Petr Pisl 2014-06-09 08:50:58 UTC
I pushed a fix for this issue. 

http://hg.netbeans.org/web-main/rev/c396a5742bb8


The fix contains unnecessary constant "_sn" which is a name of one field in the index, which is added by the indexing infrastructure. So the fix introduce ugly "dependency" on a way how the indexing infrastructure is implemented. The indexing infrastructure should allow to find index for certain fail.

I have created enhancement for Indexing API - issue # 244952. When it will be done, this fix can be rewritten and use the new ability of the Indexing API.
Comment 6 Tomas Zezula 2014-06-23 09:23:57 UTC
Rewritten to a parsing.api QuerySupport.Query API:
jet-main f9170ba8a3bd
Comment 7 Quality Engineering 2014-06-25 02:31:09 UTC
Integrated into 'main-silver', will be available in build *201406250001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/f9170ba8a3bd
User: Tomas Zezula <tzezula@netbeans.org>
Log: #244678:CodeCompletion took 11854 ms.