Bug 421328 - Performance issue with TraitUtils.parse()
Summary: Performance issue with TraitUtils.parse()
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Kaloyan Raev CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2013-11-08 07:51 EST by Kaloyan Raev CLA
Modified: 2020-05-14 11:18 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kaloyan Raev CLA 2013-11-08 07:51:08 EST
The TraitUtils.parse() method traverse source modules using an AST visitor with inefficient implementation.

This method parses source module to find trait use statements. According to the definition of traits [1], trait use statements are defined directly inside class declaration. The implementation of the AST visitor can be optimized to meet this definition and at the same time to avoid traversing the AST tree deeper than necessary.

The TraitUtils.parse() method is used by utilities like TraitUtils.getTraitMethods() and TraitUtils.getTraitFields(), which in turn are used by more generic utilities like PHPModelUtils.getTypeMethods() and PHPModelUtils.getFieldMethods(). So, the impact of the performance of TraitUtils.parse() is pretty widespread.

[1] http://php.net/manual/en/language.oop5.traits.php
Comment 1 Kaloyan Raev CLA 2013-11-08 07:55:56 EST
Changed pushed to Gerrit: https://git.eclipse.org/r/18220
Comment 2 Jacek Pospychala CLA 2013-11-12 13:32:00 EST
Gerrit change merged:
https://git.eclipse.org/r/#/c/18220/

thank you Kaloyan for the contribution!
Comment 3 Kaloyan Raev CLA 2013-11-18 04:10:46 EST
I found an issue with my change. I wrongly assumed that PHP classes can be declared only in the global scope, while in reality they can appear also in if-then-else, for/while loops and other kinds of blocks.

I'll push a correction soon.
Comment 4 Kaloyan Raev CLA 2013-11-18 04:51:52 EST
Here is the new change in Gerrit: https://git.eclipse.org/r/18484/

There is a new TypeDeclarationVisitor implement that focuses only on visiting classes, interfaces and traits with optimized performance. The main gain comes from the fact that PHP types cannot be nested.

The TraitUseStatementVisitor now extends the TypeDeclarationVisitor. 

Tests added to cover the problematic cases from the initial patch.
Comment 5 Jacek Pospychala CLA 2013-11-19 13:22:41 EST
Your change merged into master.
Great work Kaloyan!
Comment 6 Sylvia Tancheva CLA 2015-06-08 05:55:52 EDT
Closing