Skip to content

[JENKINS-76028] Add NavigableMap support for CopyOnWriteMap.Tree#10997

Merged
krisstern merged 1 commit intojenkinsci:masterfrom
dukhlov:refactor-lazy-loading-part3
Sep 2, 2025
Merged

[JENKINS-76028] Add NavigableMap support for CopyOnWriteMap.Tree#10997
krisstern merged 1 commit intojenkinsci:masterfrom
dukhlov:refactor-lazy-loading-part3

Conversation

@dukhlov
Copy link
Contributor

@dukhlov dukhlov commented Aug 20, 2025

See JENKINS-76028.

Optimise AbstractLazyLoadRunMap's search, firstKey, lastKey methods using NavigableMap features

Simplify wrapping with BuildReferenceMapAdapter by introducing single configuration class BuildReferenceMapAdapter.Resolver

Make CopyOnWriteMap.Tree.getView method protected (was public)

Testing done

Manual testing on a local setup, jenkins PR automation tests

Proposed changelog entries

  • Expose NavigableMap interface from CopyOnWrite.Tree map
  • Optimise AbstractLazyLoadRunMap.search() method

Proposed changelog category

/label internal

Proposed upgrade guidelines

N/A

Submitter checklist

  • The Jira issue, if it exists, is well-described.
  • The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood (see examples). Fill in the Proposed upgrade guidelines section only if there are breaking changes or changes that may require extra steps from users during upgrade.
  • There is automated testing or an explanation as to why this change has no tests.
  • New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadocs, as appropriate.
  • New deprecations are annotated with @Deprecated(since = "TODO") or @Deprecated(forRemoval = true, since = "TODO"), if applicable.
  • New or substantially changed JavaScript is not defined inline and does not call eval to ease future introduction of Content Security Policy (CSP) directives (see documentation).
  • For dependency updates, there are links to external changelogs and, if possible, full differentials.
  • For new APIs and extension points, there is a link to at least one consumer.

Desired reviewers

@jglick, @timja

Before the changes are marked as ready-for-merge:

Maintainer checklist

  • There are at least two (2) approvals for the pull request and no outstanding requests for change.
  • Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
  • Changelog entries in the pull request title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood.
  • Proper changelog labels are set so that the changelog can be generated automatically.
  • If the change needs additional upgrade steps from users, the upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the pull request title (see example).
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

@dukhlov dukhlov force-pushed the refactor-lazy-loading-part3 branch 7 times, most recently from ad1ab81 to b63bd98 Compare August 24, 2025 18:43
@dukhlov dukhlov marked this pull request as ready for review August 24, 2025 20:13
@dukhlov dukhlov changed the title Add NavigableMap support for CopyOnWriteMap.Tree [JENKINS-76028] Add NavigableMap support for CopyOnWriteMap.Tree Aug 24, 2025
@dukhlov dukhlov force-pushed the refactor-lazy-loading-part3 branch from b63bd98 to bdad5a8 Compare August 24, 2025 20:41
Optimize AbstractLazyLoadRunMap's search, firstKey, lastKey methods.

Simplify wrapping with BuildReferenceMapAdapter by introducing single
configuration class BuildReferenceMapAdapter.Resolver.

Make CopyOnWriteMap.Tree.getView method protected (was public).
@dukhlov dukhlov force-pushed the refactor-lazy-loading-part3 branch from bdad5a8 to ea3b238 Compare August 24, 2025 22:35
@jeromepochat
Copy link
Contributor

Hi!

I don't exactly know where Jenkins benefits from this optimization, but I've done some microbenchmarks around RunMap (which extends the optimized AbstractLazyLoadRunMap) and confirm the performance improvement. 🎉

class RunMapTest {

    // ...

    @Test
    void benchmark() throws Exception {
        FreeStyleProject p = r.createFreeStyleProject();
        RunMap<FreeStyleBuild> map = new RunMap<>(p);

        // Populate the map
        int count = 100_000;
        for (int i = 0; i < count; i++) {
            map.put(i, new FreeStyleBuild(p));
        }

        // Perform searches in both directions
        Instant start = Instant.now();
        for (int i = 0; i < count / 2; i++) {
            if (i % 2 == 0) {
                map.search(i, Direction.ASC);
            } else {
                map.search(count - i - 1, Direction.DESC);
            }
        }
        Instant stop = Instant.now();
        System.out.println("Benchmark took: " + Duration.between(start, stop).toMillis() + " ms");
    }
}
❯ mvn test -pl core,test -Dtest=RunMapTest#benchmark
  • Before: Benchmark took: 18174 ms
  • After: Benchmark took: 77 ms

Copy link

@A1exKH A1exKH left a comment

Choose a reason for hiding this comment

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

LGTM.

@NotMyFault NotMyFault requested a review from a team August 30, 2025 19:52
Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

Thanks!


/label ready-for-merge


This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback.

Thanks!

@comment-ops-bot comment-ops-bot bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Sep 1, 2025
@krisstern krisstern merged commit 3a6949d into jenkinsci:master Sep 2, 2025
18 checks passed
@dukhlov dukhlov deleted the refactor-lazy-loading-part3 branch September 4, 2025 15:05
@mawinter69
Copy link
Contributor

Not sure if this is the cause for JENKINS-76202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants