Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-35098] Disable AutoBrowserHolder by default to improve the changelog rendering performance #2371

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/model/AbstractProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import static hudson.scm.PollingResult.*;
import hudson.scm.SCM;
import hudson.scm.SCMRevisionState;
import hudson.scm.SCMS;
import hudson.search.SearchIndexBuilder;
import hudson.security.ACL;
import hudson.security.Permission;
Expand Down Expand Up @@ -1860,7 +1861,7 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio

authToken = BuildAuthorizationToken.create(req);

setScm(req.bindJSON(SCM.class, json.getJSONObject("scm")));
setScm(SCMS.parseSCM(req,this));

for (Trigger t : triggers())
t.stop();
Expand Down
88 changes: 88 additions & 0 deletions core/src/main/java/hudson/scm/AutoBrowserHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.scm;

import hudson.model.AbstractProject;
import jenkins.model.Jenkins;

/**
* Maintains the automatically inferred {@link RepositoryBrowser} instance.
*
* <p>
* To reduce the user's work, Hudson tries to infer applicable {@link RepositoryBrowser}
* from configurations of other jobs. But this needs caution &mdash; for example,
* such inferred {@link RepositoryBrowser} must be recalculated whenever
* a job configuration changes somewhere.
*
* <p>
* This class makes such tracking easy by hiding this logic.
* @deprecated Disabled by default: JENKINS-35098
*/
@Deprecated
final class AutoBrowserHolder {
private int cacheGeneration;
private RepositoryBrowser cache;
private SCM owner;

public AutoBrowserHolder(SCM owner) {
this.owner = owner;
}

public RepositoryBrowser get() {
if (cacheGeneration == -1) {
return cache;
}
SCMDescriptor<?> d = owner.getDescriptor();
RepositoryBrowser<?> dflt = owner.guessBrowser();
if (dflt != null) {
cache = dflt;
cacheGeneration = -1;
return cache;
}
int g = d.generation;
if(g!=cacheGeneration) {
cacheGeneration = g;
cache = infer();
}
return cache;
}

/**
* Picks up a {@link RepositoryBrowser} that matches the
* given {@link SCM} from existing other jobs.
*
* @return
* null if no applicable configuration was found.
*/
private RepositoryBrowser infer() {
for( AbstractProject p : Jenkins.getInstance().getAllItems(AbstractProject.class) ) {
SCM scm = p.getScm();
if (scm!=null && scm.getClass()==owner.getClass() && scm.getBrowser()!=null &&
((SCMDescriptor)scm.getDescriptor()).isBrowserReusable(scm,owner)) {
return scm.getBrowser();
}
}
return null;
}
}
19 changes: 18 additions & 1 deletion core/src/main/java/hudson/scm/SCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@
@ExportedBean
public abstract class SCM implements Describable<SCM>, ExtensionPoint {

/** JENKINS-35098: discouraged */
@SuppressWarnings("FieldMayBeFinal")
private static boolean useAutoBrowserHolder = Boolean.getBoolean(SCM.class.getName() + ".useAutoBrowserHolder");
Copy link
Member

Choose a reason for hiding this comment

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

Please use SystemProperties.getBoolean() (new API in 2.4)

/**
* Stores {@link AutoBrowserHolder}. Lazily created.
* @deprecated Unused by default.
*/
private transient AutoBrowserHolder autoBrowserHolder;

/**
* Expose {@link SCM} to the remote API.
*/
Expand Down Expand Up @@ -121,12 +130,20 @@ public String getType() {
* controlled by this {@link SCM}.
* @see #guessBrowser
*/
@SuppressWarnings("deprecation")
@Exported(name="browser")
public final @CheckForNull RepositoryBrowser<?> getEffectiveBrowser() {
RepositoryBrowser<?> b = getBrowser();
if(b!=null)
return b;
return guessBrowser();
if (useAutoBrowserHolder) {
if (autoBrowserHolder == null) {
autoBrowserHolder = new AutoBrowserHolder(this);
}
return autoBrowserHolder.get();
} else {
return guessBrowser();
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/scm/SCMDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public abstract class SCMDescriptor<T extends SCM> extends Descriptor<SCM> {
* This is used to invalidate cache of {@link SCM#getEffectiveBrowser}. Due to the lack of synchronization and serialization,
* this field doesn't really count the # of instances created to date,
* but it's good enough for the cache invalidation.
* @deprecated No longer used.
* @deprecated No longer used by default.
*/
@Deprecated
public volatile int generation = 1;
Expand Down Expand Up @@ -104,7 +104,7 @@ public void load() {
* @return
* true if the two given SCM configurations are similar enough
* that they can reuse {@link RepositoryBrowser} between them.
* @deprecated No longer used. {@link SCM#getKey} could be used to implement similar features if needed.
* @deprecated No longer used by default. {@link SCM#getKey} could be used to implement similar features if needed.
*/
@Deprecated
public boolean isBrowserReusable(T x, T y) {
Expand Down
14 changes: 4 additions & 10 deletions core/src/main/java/hudson/scm/SCMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@
* List of all installed SCMs.
*
* @author Kohsuke Kawaguchi
* @deprecated No longer contains anything nondeprecated.
*/
@Deprecated
public class SCMS {
/**
* List of all installed SCMs.
Expand All @@ -55,16 +53,12 @@ public class SCMS {
*
* @param target
* The project for which this SCM is configured to.
* @deprecated Suffices to use {@link StaplerRequest#bindJSON(java.lang.Class, net.sf.json.JSONObject)}
*/
@Deprecated
@SuppressWarnings("deprecation")
public static SCM parseSCM(StaplerRequest req, AbstractProject target) throws FormException, ServletException {
String scm = req.getParameter("scm");
if(scm==null) return new NullSCM();

int scmidx = Integer.parseInt(scm);
SCMDescriptor<?> d = SCM._for(target).get(scmidx);
return d.newInstance(req, req.getSubmittedForm().getJSONObject("scm"));
SCM scm = req.bindJSON(SCM.class, req.getSubmittedForm().getJSONObject("scm"));
Copy link
Member

Choose a reason for hiding this comment

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

@oleg-nenashev @jglick Could this have caused JENKINS-35906?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably. No longer calling SCMDescriptor.newInstance overloads. They are a bad idea of course and unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Possibly could use DescriptorExtensionList.newInstanceFromRadioList for this purpose.

scm.getDescriptor().generation++;
return scm;
}

/**
Expand Down