IntelliJ IDEA  Architecture and Performance Dmit ry Jemerov Development Lead JetBrains, Inc. ht tp://www.jetbrains.com/
<ul><li>Learn about performance optimization techniques used in IntelliJ IDEA </li></ul><ul><li>Understand the factors aff...
Agenda <ul><li>Elements of Architecture </li></ul><ul><li>Performance Tips </li></ul>
Component Model <ul><li>Hierarchy of PicoContainer containers </li></ul><ul><li>3 levels of components: application, proje...
Services: Lazy Loading <ul><li>No strict lifecycle: loaded on demand </li></ul><ul><li>Key for loading service is FQN of s...
Disposer Hierarchy <ul><li>Tree of dependencies between objects </li></ul><ul><li>Disposing of parent object also disposes...
Persistent File System <ul><li>Complete snapshot of files under project stored in single file </li></ul><ul><li>Improves s...
File System Synchronization <ul><li>On startup, background synchronization of all files under project is performed </li></...
Indexing Framework <ul><li>Indexer builds list of key/value pairs from file content </li></ul><ul><li>Keys and values are ...
Indexing Framework Usages <ul><li>Word index </li></ul><ul><ul><li>Key: hashcode of word </li></ul></ul><ul><ul><li>Value:...
PSI <ul><li>Program Source Interface </li></ul><ul><li>Read/write access to program syntax tree </li></ul><ul><li>From dir...
Building PSI from Source <ul><li>Lexer produces stream of tokens </li></ul><ul><ul><li>Lexers usually generated with Flex ...
Updating PSI <ul><li>Syntax highlighting based on lexer </li></ul><ul><ul><li>Synchronous and incremental </li></ul></ul><...
PSI Stubs <ul><li>Compact binary serialization of externally visible interface of file </li></ul><ul><li>Can be provided f...
Stub Indexes <ul><li>For a stub element, a number of keys for different indexes can be provided </li></ul><ul><li>PSI elem...
Background Analysis <ul><li>Multiple passes with different priorities </li></ul><ul><ul><li>Faster analysis performed firs...
Multi-Core Support <ul><li>Inspections: Different inspections for same file run in parallel on multiple cores </li></ul><u...
Multi-Core Support Challenges <ul><li>Deadlocks </li></ul><ul><ul><li>Lock ordering policies must be followed consistently...
Agenda <ul><li>Elements of Architecture </li></ul><ul><li>Performance Tips </li></ul>
Performance Tips: System <ul><li>IDEA is heavily IO-bound </li></ul><ul><li>Do not store sources, caches or system directo...
Performance Tips: JVM <ul><li>Use JDK 6 </li></ul><ul><li>In –server mode, increasing –Xmx helps IDEA’s caches live longer...
Performance Tips: IDE <ul><li>Use latest version </li></ul><ul><li>Disable unused plugins </li></ul><ul><li>Exclude unneed...
Performance Tips: IDE (2) <ul><li>Do not disable “Synchronize files on frame activation” </li></ul><ul><li>Switch Project ...
Reporting Performance Issues <ul><li>Enable built-in YourKit profiling </li></ul><ul><ul><li>-agentlib:yjpagent in idea.ex...
For More Information <ul><li>IntelliJ IDEA:  </li></ul><ul><ul><li>http://www.jetbrains.com/idea/ </li></ul></ul><ul><li>P...
Q&A Dmitry Jemerov [email_address]
IntelliJ IDEA  Architecture and Performance Dmit ry Jemerov Development Lead JetBrains, Inc. ht tp://www.jetbrains.com/
Upcoming SlideShare
Loading in...5
×

IntelliJ IDEA Architecture and Performance

8,861

Published on

Slides from JUG.RU presentation in Moscow on 12.04.2008

Published in: Technology

IntelliJ IDEA Architecture and Performance

  1. 1. IntelliJ IDEA Architecture and Performance Dmit ry Jemerov Development Lead JetBrains, Inc. ht tp://www.jetbrains.com/
  2. 2. <ul><li>Learn about performance optimization techniques used in IntelliJ IDEA </li></ul><ul><li>Understand the factors affecting IntelliJ IDEA performance in normal use </li></ul>
  3. 3. Agenda <ul><li>Elements of Architecture </li></ul><ul><li>Performance Tips </li></ul>
  4. 4. Component Model <ul><li>Hierarchy of PicoContainer containers </li></ul><ul><li>3 levels of components: application, project and module </li></ul><ul><li>Components have strictly defined lifecycle </li></ul><ul><li>Registration through XML configuration files (typically) </li></ul>
  5. 5. Services: Lazy Loading <ul><li>No strict lifecycle: loaded on demand </li></ul><ul><li>Key for loading service is FQN of service interface </li></ul><ul><li>Not even classloading happens before service is accessed </li></ul><ul><li>Service may have persistent settings which are automatically loaded on instantiation </li></ul>
  6. 6. Disposer Hierarchy <ul><li>Tree of dependencies between objects </li></ul><ul><li>Disposing of parent object also disposes of all its children </li></ul><ul><li>Relationships stored outside of object: no common base class required </li></ul><ul><li>Typical actions on dispose: </li></ul><ul><ul><li>Detaching listeners </li></ul></ul><ul><ul><li>Stopping timers/background threads </li></ul></ul><ul><ul><li>UI component cleanup </li></ul></ul>
  7. 7. Persistent File System <ul><li>Complete snapshot of files under project stored in single file </li></ul><ul><li>Improves startup performance </li></ul><ul><ul><li>Directory tree walk is very expensive, especially on Windows </li></ul></ul><ul><li>Provides old content when file is changed </li></ul><ul><ul><li>Required for update of indexes </li></ul></ul><ul><li>Supports custom persistent attributes </li></ul>
  8. 8. File System Synchronization <ul><li>On startup, background synchronization of all files under project is performed </li></ul><ul><li>Watching for file system notifications </li></ul><ul><ul><li>ReadDirectoryChangesW() on Windows </li></ul></ul><ul><ul><li>/dev/fsevents on Mac (fslogger) </li></ul></ul><ul><ul><li>Linux has no API for recursive watching, requires keeping a file handle for every directory under project </li></ul></ul>
  9. 9. Indexing Framework <ul><li>Indexer builds list of key/value pairs from file content </li></ul><ul><li>Keys and values are arbitrary beans </li></ul><ul><li>Indexer provides binary serialization for keys and values </li></ul><ul><li>Application-level </li></ul><ul><ul><li>same file under different projects indexed only once </li></ul></ul>
  10. 10. Indexing Framework Usages <ul><li>Word index </li></ul><ul><ul><li>Key: hashcode of word </li></ul></ul><ul><ul><li>Value: occurrence mask </li></ul></ul><ul><ul><ul><li>identifier, comment, string literal </li></ul></ul></ul><ul><ul><li>Used for Find in Path, Find Usages etc. </li></ul></ul><ul><li>TODO index </li></ul><ul><li>File name index </li></ul><ul><li>etc. </li></ul>
  11. 11. PSI <ul><li>Program Source Interface </li></ul><ul><li>Read/write access to program syntax tree </li></ul><ul><li>From directories down to individual tokens </li></ul><ul><li>Works across languages </li></ul><ul><ul><li>Some elements (whitespace, comment etc.) used by all languages </li></ul></ul>
  12. 12. Building PSI from Source <ul><li>Lexer produces stream of tokens </li></ul><ul><ul><li>Lexers usually generated with Flex </li></ul></ul><ul><li>Parser builds syntax tree </li></ul><ul><ul><li>Usually hand-written recursive descent </li></ul></ul><ul><ul><li>Table-driven parsers seldom provide adequate error recovery </li></ul></ul><ul><li>Language creates PSI elements for syntax tree nodes </li></ul>
  13. 13. Updating PSI <ul><li>Syntax highlighting based on lexer </li></ul><ul><ul><li>Synchronous and incremental </li></ul></ul><ul><li>PSI updates triggered by background analysis </li></ul><ul><ul><li>Starts after 300 ms of inactivity </li></ul></ul><ul><ul><li>Cancelled by next user action </li></ul></ul><ul><li>Syntax tree (AST) is built for entire file </li></ul><ul><li>PSI is replaced for changed parts of AST </li></ul>
  14. 14. PSI Stubs <ul><li>Compact binary serialization of externally visible interface of file </li></ul><ul><li>Can be provided for any language </li></ul><ul><li>Must be sufficient for resolving imported declarations without parsing imported files </li></ul><ul><li>PSI elements can exist in two modes: stub-based and AST-based </li></ul><ul><ul><li>Switching from stubs to AST is transparent for the client </li></ul></ul>
  15. 15. Stub Indexes <ul><li>For a stub element, a number of keys for different indexes can be provided </li></ul><ul><li>PSI elements can then be retrieved by such keys </li></ul><ul><li>Sample indexes: </li></ul><ul><ul><li>Classes by name (Goto Class) </li></ul></ul><ul><ul><li>Symbols by name (Goto Symbol) </li></ul></ul><ul><ul><li>Classes by superclass name (Goto Implementations) </li></ul></ul>
  16. 16. Background Analysis <ul><li>Multiple passes with different priorities </li></ul><ul><ul><li>Faster analysis performed first </li></ul></ul><ul><li>Separate high-priority passes for highlighting only visible area </li></ul><ul><li>Minimum affected scope is re-analyzed after change </li></ul><ul><li>Cancellation on user activity </li></ul><ul><ul><li>Cancellation flag checked in many low-level operations, exception thrown and caught on top level </li></ul></ul>
  17. 17. Multi-Core Support <ul><li>Inspections: Different inspections for same file run in parallel on multiple cores </li></ul><ul><li>Find Usages: Different occurrences of target identifier are checked in parallel </li></ul><ul><li>JobScheduler API </li></ul><ul><ul><li>Starts # of threads depending on # of available CPU cores </li></ul></ul><ul><ul><li>Distributes work units between threads </li></ul></ul><ul><ul><li>Waits until all work units processed </li></ul></ul>
  18. 18. Multi-Core Support Challenges <ul><li>Deadlocks </li></ul><ul><ul><li>Lock ordering policies must be followed consistently </li></ul></ul><ul><li>Lock contention </li></ul><ul><ul><li>Lock granularity must be reduced to ensure that all threads can run in parallel </li></ul></ul><ul><ul><li>YourKit used for profiling </li></ul></ul><ul><li>Creating too many sync objects </li></ul><ul><ul><li>Lock pooling: fixed size pool of locks evenly distributed between all objects </li></ul></ul>
  19. 19. Agenda <ul><li>Elements of Architecture </li></ul><ul><li>Performance Tips </li></ul>
  20. 20. Performance Tips: System <ul><li>IDEA is heavily IO-bound </li></ul><ul><li>Do not store sources, caches or system directories on network drives </li></ul><ul><li>Disable antivirus scanning for system directory </li></ul><ul><li>Regularly run disk defragmenter </li></ul><ul><li>Turn off Windows System Restore </li></ul>
  21. 21. Performance Tips: JVM <ul><li>Use JDK 6 </li></ul><ul><li>In –server mode, increasing –Xmx helps IDEA’s caches live longer </li></ul><ul><li>Parallel GC helps on multicore machines </li></ul><ul><li>However : May cause stability issues. YMMV. </li></ul>
  22. 22. Performance Tips: IDE <ul><li>Use latest version </li></ul><ul><li>Disable unused plugins </li></ul><ul><li>Exclude unneeded folders </li></ul><ul><li>Set version control to None for generated code </li></ul><ul><li>Avoid large number of unversioned files </li></ul>
  23. 23. Performance Tips: IDE (2) <ul><li>Do not disable “Synchronize files on frame activation” </li></ul><ul><li>Switch Project view to “Project” rather than “Packages” </li></ul><ul><li>Disable expensive inspections </li></ul><ul><li>Disable framework-specific validation on Make </li></ul><ul><li>Do not use method breakpoints </li></ul>
  24. 24. Reporting Performance Issues <ul><li>Enable built-in YourKit profiling </li></ul><ul><ul><li>-agentlib:yjpagent in idea.exe.vmoptions </li></ul></ul><ul><ul><li>On by default in EAP builds </li></ul></ul><ul><li>Capture snapshot </li></ul><ul><li>Create JIRA issue and attach snapshot </li></ul><ul><ul><li>http://www.jetbrains.net/jira </li></ul></ul><ul><li>Also possible to use standalone YourKit </li></ul><ul><ul><li>For example, for startup profiling </li></ul></ul>
  25. 25. For More Information <ul><li>IntelliJ IDEA: </li></ul><ul><ul><li>http://www.jetbrains.com/idea/ </li></ul></ul><ul><li>Plugin Development Kit: </li></ul><ul><ul><li>http://www.jetbrains.com/idea/plugins/plugin_developers.html </li></ul></ul><ul><li>Discussion forums: </li></ul><ul><ul><li>http://www.intellij.net/forums/ </li></ul></ul>
  26. 26. Q&A Dmitry Jemerov [email_address]
  27. 27. IntelliJ IDEA Architecture and Performance Dmit ry Jemerov Development Lead JetBrains, Inc. ht tp://www.jetbrains.com/

×