GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Per level tracking simplification and performance improvements by andimarek · Pull Request #4128 · graphql-java/graphql-java

Conversation

@andimarek

@andimarek andimarek commented Sep 23, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This PR fundamentally refactors the PerLevelDataLoaderDispatchStrategy

first it simplifies a lot what is actually tracked and then it get rids of synchronized/locks and uses a CAS mechanism instead.

First Pr that implemented a lock free chained data loader tracking: #4123

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
andimarek added 2 commits September 23, 2025 14:27
@andimarek
nearly works
9566326
@andimarek
works except dataloader in defer
07b1600
@github-actions

github-actions Bot commented Sep 23, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Test Results

  326 files    326 suites   3m 30s ⏱️
5 022 tests 5 016 ✅ 6 💤 0 ❌
5 111 runs  5 105 ✅ 6 💤 0 ❌

Results for commit 2eecad7.

♻️ This comment has been updated with latest results.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

andimarek added 9 commits September 24, 2025 11:32
@andimarek
working with simpler mode except batching, defer, subscription
56a39df
@andimarek
subscription works
0436e5d
@andimarek
fix defer support
b25724b
@andimarek
cleanup
117ebe1
@andimarek
cleanup
a5d29a6
@andimarek
no per level tracking anymore
2686c32
@andimarek
cleanup
a67e56b
@andimarek
no synchronized/locking anymore
2da8fef
@andimarek
cleanup and comment
009fcb8
@andimarek andimarek changed the title Per level tracking refactor Per level tracking simplification and performance improvements Sep 24, 2025
@andimarek
andimarek requested a review from Copilot September 24, 2025 20:23
Copilot AI reviewed Sep 24, 2025
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the PerLevelDataLoaderDispatchStrategy to simplify level tracking and improve performance by replacing synchronized blocks with lock-free compare-and-swap (CAS) operations. The refactoring reduces the complexity of tracking mechanisms and introduces atomic operations for thread safety.

  • Simplified per-level tracking by consolidating multiple tracking maps into a single state object
  • Replaced synchronized blocks with CAS-based atomic operations for better performance
  • Restructured subscription execution flow with separate callback methods

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
PerLevelDataLoaderDispatchStrategy.java Core refactoring with new StateForLevel class and CAS-based updates
LevelMap.java Updated toString format with additional brackets
DataLoaderDispatchStrategy.java Split subscription callback into separate methods
SubscriptionExecutionStrategy.java Updated to use new subscription callback methods
ExecutionStrategy.java Reordered executeObject call timing
LevelMapTest.groovy Updated test assertions for new toString format
DataLoaderPerformance.java Removed benchmark annotations and added main method for testing

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...in/java/graphql/execution/instrumentation/dataloader/PerLevelDataLoaderDispatchStrategy.java
return true;
private boolean isLevelReady(int level, CallStack callStack) {
// we expect that parent has been dispatched and that all parents fields are completed
// all parent fields completed means all parent parent on completions finished calls must have happened

Copilot AI Sep 24, 2025

Copy link

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can cause an IndexOutOfBoundsException when level is less than 2. The method isLevelReady should validate that level >= 2 before accessing level - 2.

Suggested change
// all parent fields completed means all parent parent on completions finished calls must have happened
// all parent fields completed means all parent parent on completions finished calls must have happened
if (level < 2) {
return false;
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot uses AI. Check for mistakes.
Comment thread ...in/java/graphql/execution/instrumentation/dataloader/PerLevelDataLoaderDispatchStrategy.java Outdated
if (callStack.tryUpdateLevel(curLevel, currentState, currentState.increaseHappenedExecuteObjectCalls())) {
return;
}

Copilot AI Sep 24, 2025

Copy link

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This infinite loop without backoff or yield could cause excessive CPU usage under high contention. Consider adding a short pause or using exponential backoff between CAS retry attempts.

Suggested change
// Avoid excessive CPU usage under contention
Thread.onSpinWait();

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot uses AI. Check for mistakes.
Comment thread ...in/java/graphql/execution/instrumentation/dataloader/PerLevelDataLoaderDispatchStrategy.java
CallStack.StateForLevel currentState = callStack.get(level);
if (callStack.tryUpdateLevel(level, currentState, currentState.increaseHappenedCompletionFinishedCount())) {
break;
}

Copilot AI Sep 24, 2025

Copy link

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another infinite CAS retry loop without backoff. This could lead to high CPU usage under contention. Consider adding yield or backoff strategy.

Suggested change
}
}
Thread.yield();

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot uses AI. Check for mistakes.
andimarek added 2 commits September 25, 2025 06:54
@andimarek
add Thread.onSpinWait to indicate active waiting
ab06e30
Add assertion
@andimarek
remove Thread.onSpinWait again as not clear this is needed or has may…
2eecad7
…be negative effects
@andimarek
andimarek merged commit bf37527 into master Sep 24, 2025
@andimarek andimarek added this to the 25.x breaking changes milestone Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

25.x breaking changes

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@andimarek
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.