Skip to content

Commit e6e0d7a

Browse files
authored
perf: optimized the javadoc from binary and filter common 3rd lib (#931)
1 parent 7c460e8 commit e6e0d7a

File tree

1 file changed

+67
-11
lines changed

1 file changed

+67
-11
lines changed

jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/parser/ContextResolver.java

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,57 @@ public class ContextResolver {
6363
SKIP_COMMON_JDK_PACKAGES.add("java.text"); // DateFormat, SimpleDateFormat, etc.
6464
SKIP_COMMON_JDK_PACKAGES.add("java.sql"); // Connection, ResultSet, etc.
6565
SKIP_COMMON_JDK_PACKAGES.add("javax.sql"); // DataSource, etc.
66+
67+
// Java EE / Jakarta EE - Well-known enterprise packages
68+
SKIP_COMMON_JDK_PACKAGES.add("javax.servlet"); // Servlet API
69+
SKIP_COMMON_JDK_PACKAGES.add("javax.annotation"); // @PostConstruct, @PreDestroy, etc.
70+
SKIP_COMMON_JDK_PACKAGES.add("javax.persistence"); // JPA annotations
71+
SKIP_COMMON_JDK_PACKAGES.add("javax.inject"); // @Inject
72+
SKIP_COMMON_JDK_PACKAGES.add("javax.validation"); // Bean Validation
73+
SKIP_COMMON_JDK_PACKAGES.add("jakarta.servlet"); // Jakarta Servlet
74+
SKIP_COMMON_JDK_PACKAGES.add("jakarta.persistence"); // Jakarta JPA
75+
76+
// Spring Framework - Extremely common and well-documented
77+
SKIP_COMMON_JDK_PACKAGES.add("org.springframework.stereotype"); // @Component, @Service, @Repository, @Controller
78+
SKIP_COMMON_JDK_PACKAGES.add("org.springframework.beans"); // @Autowired, BeanFactory
79+
SKIP_COMMON_JDK_PACKAGES.add("org.springframework.context"); // ApplicationContext, @Configuration
80+
SKIP_COMMON_JDK_PACKAGES.add("org.springframework.web.bind"); // @RequestMapping, @PathVariable, etc.
81+
SKIP_COMMON_JDK_PACKAGES.add("org.springframework.boot"); // SpringApplication, @SpringBootApplication
82+
SKIP_COMMON_JDK_PACKAGES.add("org.springframework.data.jpa"); // JpaRepository
83+
SKIP_COMMON_JDK_PACKAGES.add("org.springframework.data.repository"); // CrudRepository
84+
SKIP_COMMON_JDK_PACKAGES.add("org.springframework.transaction"); // @Transactional
85+
SKIP_COMMON_JDK_PACKAGES.add("org.springframework.security"); // Spring Security annotations
86+
87+
// Testing frameworks - Very common and well-documented
88+
SKIP_COMMON_JDK_PACKAGES.add("org.junit"); // JUnit 4/5 - @Test, assertions
89+
SKIP_COMMON_JDK_PACKAGES.add("org.junit.jupiter"); // JUnit 5 specific
90+
SKIP_COMMON_JDK_PACKAGES.add("org.testng"); // TestNG
91+
SKIP_COMMON_JDK_PACKAGES.add("org.mockito"); // Mockito - mock(), when(), verify()
92+
SKIP_COMMON_JDK_PACKAGES.add("org.assertj"); // AssertJ fluent assertions
93+
SKIP_COMMON_JDK_PACKAGES.add("org.hamcrest"); // Hamcrest matchers
94+
95+
// Lombok - Code generation library (Copilot understands these annotations very well)
96+
SKIP_COMMON_JDK_PACKAGES.add("lombok"); // @Data, @Getter, @Setter, @Builder, etc.
97+
98+
// Logging frameworks - Very standard APIs
99+
SKIP_COMMON_JDK_PACKAGES.add("org.slf4j"); // SLF4J - Logger, LoggerFactory
100+
SKIP_COMMON_JDK_PACKAGES.add("org.apache.logging.log4j"); // Log4j 2
101+
SKIP_COMMON_JDK_PACKAGES.add("org.apache.log4j"); // Log4j 1.x
102+
SKIP_COMMON_JDK_PACKAGES.add("java.util.logging"); // JUL - java.util.logging
103+
104+
// Jackson - JSON processing (very common)
105+
SKIP_COMMON_JDK_PACKAGES.add("com.fasterxml.jackson.annotation"); // @JsonProperty, @JsonIgnore
106+
SKIP_COMMON_JDK_PACKAGES.add("com.fasterxml.jackson.core"); // JsonParser, JsonGenerator
107+
SKIP_COMMON_JDK_PACKAGES.add("com.fasterxml.jackson.databind"); // ObjectMapper
108+
109+
// Google Guava - Well-known utility library
110+
SKIP_COMMON_JDK_PACKAGES.add("com.google.common.collect"); // ImmutableList, ImmutableMap, etc.
111+
SKIP_COMMON_JDK_PACKAGES.add("com.google.common.base"); // Preconditions, Strings, etc.
112+
113+
// Apache Commons - Well-known utility libraries
114+
SKIP_COMMON_JDK_PACKAGES.add("org.apache.commons.lang3"); // StringUtils, etc.
115+
SKIP_COMMON_JDK_PACKAGES.add("org.apache.commons.collections4"); // CollectionUtils
116+
SKIP_COMMON_JDK_PACKAGES.add("org.apache.commons.io"); // IOUtils, FileUtils
66117
}
67118

68119
/**
@@ -821,20 +872,25 @@ public static String generateClassDescription(org.eclipse.jdt.core.IType type, S
821872
*/
822873
private static String extractRelevantJavaDocContent(org.eclipse.jdt.core.IType type, IProgressMonitor monitor) {
823874
try {
875+
// Performance optimization: Skip JavaDoc extraction for binary types
876+
// getAttachedJavadoc() is EXTREMELY expensive for binary types:
877+
// - Requires reading from JAR files (I/O overhead)
878+
// - May trigger Maven artifact download from remote repositories (network)
879+
// - Involves HTML parsing and DOM manipulation (CPU intensive)
880+
// Binary types from JARs are typically well-known libraries that Copilot already understands
881+
if (type.isBinary()) {
882+
return ""; // Skip expensive JavaDoc extraction for external dependencies
883+
}
884+
824885
String rawJavadoc;
825-
boolean isHtml;
886+
boolean isHtml = false;
826887

827-
if (type.isBinary()) {
828-
rawJavadoc = type.getAttachedJavadoc(monitor);
829-
isHtml = true;
830-
} else {
831-
org.eclipse.jdt.core.ISourceRange javadocRange = type.getJavadocRange();
832-
if (javadocRange == null) {
833-
return "";
834-
}
835-
rawJavadoc = type.getCompilationUnit().getSource().substring(javadocRange.getOffset(), javadocRange.getOffset() + javadocRange.getLength());
836-
isHtml = false; // Javadoc comment from source is not HTML
888+
// Extract JavaDoc from source code (fast - no I/O, no network, no HTML parsing)
889+
org.eclipse.jdt.core.ISourceRange javadocRange = type.getJavadocRange();
890+
if (javadocRange == null) {
891+
return "";
837892
}
893+
rawJavadoc = type.getCompilationUnit().getSource().substring(javadocRange.getOffset(), javadocRange.getOffset() + javadocRange.getLength());
838894

839895
if (!isNotEmpty(rawJavadoc)) {
840896
return "";

0 commit comments

Comments
 (0)