Skip to content

More performance optimization#14695

Merged
koppor merged 3 commits into
mainfrom
refine-performance
Dec 23, 2025
Merged

More performance optimization#14695
koppor merged 3 commits into
mainfrom
refine-performance

Conversation

@koppor

@koppor koppor commented Dec 23, 2025

Copy link
Copy Markdown
Member

User description

Our build is sometimes slow.

I applied more hints from

Needs to be tested on multiple machines - we can revert if it harms.

Steps to test

gradlew --rerun-tasks compileJava on main and on this branch.

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • [/] I manually tested my changes in running JabRef (always required)
  • [/] I added JUnit tests for changes (if applicable)
  • [/] I added screenshots in the PR description (if change is visible to the user)
  • [/] I described the change in CHANGELOG.md in a way that is understandable for the average user (if change is visible to the user)
  • [/] I checked the user documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request updating file(s) in https://github.com/JabRef/user-documentation/tree/main/en.

PR Type

Enhancement


Description

  • Enable compiler forking for improved Java compilation performance

  • Configure test forking to run 100 tests per process

  • Add Gradle parallel execution and on-demand configuration

  • Refactor maxParallelForks calculation using Kotlin coerceAtLeast


Diagram Walkthrough

flowchart LR
  A["Gradle Build Configuration"] --> B["Java Compilation"]
  A --> C["Test Execution"]
  A --> D["Gradle Properties"]
  B --> B1["Enable Compiler Forking"]
  C --> C1["Fork Tests Every 100"]
  C --> C2["Optimize Parallel Forks"]
  D --> D1["Enable Parallel Execution"]
  D --> D2["Enable Configure on Demand"]
Loading

File Walkthrough

Relevant files
Enhancement
org.jabref.gradle.feature.compile.gradle.kts
Enable Java compiler forking for performance                         

build-logic/src/main/kotlin/org.jabref.gradle.feature.compile.gradle.kts

  • Enable compiler forking by setting options.isFork = true
  • Added reference documentation link for compiler performance
    optimization
+2/-0     
org.jabref.gradle.feature.test.gradle.kts
Configure test forking and parallel execution                       

build-logic/src/main/kotlin/org.jabref.gradle.feature.test.gradle.kts

  • Refactor maxParallelForks calculation using coerceAtLeast(1) for
    cleaner Kotlin syntax
  • Add forkEvery = 100 to fork tests into multiple processes
  • Added reference documentation link for test forking performance
+3/-1     
Configuration changes
gradle.properties
Enable Gradle parallel and on-demand execution                     

gradle.properties

  • Enable org.gradle.configureondemand=true for on-demand configuration
  • Enable org.gradle.parallel=true for parallel task execution
  • Added reference documentation link for parallel execution
+5/-0     

@koppor koppor added dev: build-system automerge PR is tagged with that label will be merged if workflows are green labels Dec 23, 2025
@koppor koppor enabled auto-merge December 23, 2025 10:16
jabref-machine
jabref-machine previously approved these changes Dec 23, 2025
@qodo-code-review

qodo-code-review Bot commented Dec 23, 2025

Copy link
Copy Markdown
Contributor

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review

qodo-code-review Bot commented Dec 23, 2025

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Configure memory for forked compiler

Configure memory for the forked Java compiler process to prevent potential
OutOfMemoryError during compilation. Set options.forkOptions.memoryInitialSize
and options.forkOptions.memoryMaximumSize.

build-logic/src/main/kotlin/org.jabref.gradle.feature.compile.gradle.kts [29-33]

 tasks.withType<JavaCompile>().configureEach {
     options.release = 24
     // See https://docs.gradle.org/current/userguide/performance.html#a_run_the_compiler_as_a_separate_process
     options.isFork = true
+    // Set memory options for the forked compiler process to avoid OutOfMemoryError
+    options.forkOptions.memoryInitialSize = "256m"
+    options.forkOptions.memoryMaximumSize = "2g"
 }
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: This suggestion correctly identifies that enabling compiler forking without allocating memory can lead to OutOfMemoryError on large projects, which would cause the build to fail. It improves build stability.

Medium
General
Condition forkEvery on CI guard
Suggestion Impact:The commit wraps `forkEvery = 100` (and sets `maxParallelForks`) in an `if (!CI)` block, matching the suggestion to avoid applying the optimization on CI.

code diff:

-    forkEvery = 100
+    if (!providers.environmentVariable("CI").map { it.toBoolean() }.getOrElse(false)) {
+        maxParallelForks = (Runtime.getRuntime().availableProcessors() - 1).coerceAtLeast(1)
+        forkEvery = 100
+    }

Move forkEvery = 100 inside the if block that checks for the CI environment
variable. This ensures the test forking optimization runs only on local
developer machines, not on the CI server, to improve build reliability.

build-logic/src/main/kotlin/org.jabref.gradle.feature.test.gradle.kts [22]

-forkEvery = 100
+if (!providers.environmentVariable("CI").map { it.toBoolean() }.getOrElse(false)) {
+    maxParallelForks = (Runtime.getRuntime().availableProcessors() - 1).coerceAtLeast(1)
+    forkEvery = 100
+}

[Suggestion processed]

Suggestion importance[1-10]: 8

__

Why: This is a critical suggestion for build stability. Applying forkEvery on CI without ensuring perfect test isolation can lead to flaky tests, and this change wisely restricts the optimization to local builds.

Medium
Parse CI variable as boolean
Suggestion Impact:The commit replaced the presence check on the CI env var with a boolean parse using map { it.toBoolean() }.getOrElse(false), matching the suggested logic.

code diff:

-    if (!providers.environmentVariable("CI").isPresent) {
+    if (!providers.environmentVariable("CI").map { it.toBoolean() }.getOrElse(false)) {
+        // See https://docs.gradle.org/8.1/userguide/performance.html#execute_tests_in_parallel for details.

Improve the check for the CI environment variable by parsing its boolean value
instead of just checking for its presence. Replace
!providers.environmentVariable("CI").isPresent with
!providers.environmentVariable("CI").map { it.toBoolean() }.getOrElse(false).

build-logic/src/main/kotlin/org.jabref.gradle.feature.test.gradle.kts [18-20]

-if (!providers.environmentVariable("CI").isPresent) {
+if (!providers.environmentVariable("CI").map { it.toBoolean() }.getOrElse(false)) {
     maxParallelForks = (Runtime.getRuntime().availableProcessors() - 1).coerceAtLeast(1)
 }

[Suggestion processed]

Suggestion importance[1-10]: 5

__

Why: The suggestion correctly points out that checking for the presence of the CI variable is not as robust as checking its boolean value. This change improves the logic to correctly handle cases like CI=false.

Low
  • Update

Comment thread build-logic/src/main/kotlin/org.jabref.gradle.feature.test.gradle.kts Outdated
@koppor koppor removed the automerge PR is tagged with that label will be merged if workflows are green label Dec 23, 2025
Comment thread build-logic/src/main/kotlin/org.jabref.gradle.feature.test.gradle.kts Outdated
…dle.kts

Co-authored-by: qodo-code-review[bot] <151058649+qodo-code-review[bot]@users.noreply.github.com>
@koppor koppor added the automerge PR is tagged with that label will be merged if workflows are green label Dec 23, 2025
@koppor koppor added this pull request to the merge queue Dec 23, 2025
Merged via the queue into main with commit 4a4334d Dec 23, 2025
64 checks passed
@koppor koppor deleted the refine-performance branch December 23, 2025 12:46
Siedlerchr added a commit that referenced this pull request Dec 23, 2025
* main:
  Update AI usage policy (#14698)
  Fix handling of DOIs (#14704)
  Handle ohter CrossRef response (#14696)
  Fix condition for processing closed issues/PRs
  Translate the English "change to Chinese(simplified)" to the Chinese in the warning dialog (#14690)
  More performance optimization (#14695)
  Add missing dot (and a link)
  Add link to PR template also if checklist is present, but not OK (#14694)
  Fix typo in IntelliJ code style instructions (#14693)
  Add import into new library to Welcome Tab (#14669)
  Add initial search requirements (#14633)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge PR is tagged with that label will be merged if workflows are green dev: build-system Review effort 2/5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants