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