From dd2083aa4734836164b82a86608ad8a9ec353a02 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 22 Dec 2014 16:18:44 -0500 Subject: [PATCH] [FIXED JENKINS-19392] Simpler and more efficient to use String.intern to compact fingerprint data. This should work across builds and even across jobs, and does not force us to load other builds. (cherry picked from commit 2f59ffc475dc73a9a9cd5a7596819f3242c22f6f) Conflicts: changelog.html --- .../main/java/hudson/tasks/Fingerprinter.java | 46 ++++--------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/core/src/main/java/hudson/tasks/Fingerprinter.java b/core/src/main/java/hudson/tasks/Fingerprinter.java index ef14b0d6ed..051809dfca 100644 --- a/core/src/main/java/hudson/tasks/Fingerprinter.java +++ b/core/src/main/java/hudson/tasks/Fingerprinter.java @@ -294,8 +294,7 @@ public class Fingerprinter extends Recorder implements Serializable, DependencyD public FingerprintAction(Run build, Map record) { this.build = build; - this.record = PackedMap.of(record); - compact(); + this.record = compact(record); } @Deprecated @@ -306,9 +305,8 @@ public class Fingerprinter extends Recorder implements Serializable, DependencyD public void add(Map moreRecords) { Map r = new HashMap(record); r.putAll(moreRecords); - record = PackedMap.of(r); + record = compact(r); ref = null; - compact(); } public String getIconFileName() { @@ -341,48 +339,20 @@ public class Fingerprinter extends Recorder implements Serializable, DependencyD @Override public void onLoad(Run r) { build = r; - compact(); + record = compact(record); } @Override public void onAttached(Run r) { // for historical reasons this setup is done in the constructor instead } - private void compact() { - // share data structure with nearby builds, but to keep lazy loading efficient, - // don't go back the history forever. - if (rand.nextInt(2)!=0) { - Run pb = build.getPreviousBuild(); - if (pb!=null) { - FingerprintAction a = pb.getAction(FingerprintAction.class); - if (a!=null) - compact(a); - } - } - } - - /** - * Reuse string instances from another {@link FingerprintAction} to reduce memory footprint. - */ - protected void compact(FingerprintAction a) { - Map intern = new HashMap(); // string intern map - for (Entry e : a.record.entrySet()) { - intern.put(e.getKey(),e.getKey()); - intern.put(e.getValue(),e.getValue()); - } - - Map b = new HashMap(); + /** Share data structure with other builds, mainly those of the same job. */ + private PackedMap compact(Map record) { + Map b = new HashMap(); for (Entry e : record.entrySet()) { - String k = intern.get(e.getKey()); - if (k==null) k = e.getKey(); - - String v = intern.get(e.getValue()); - if (v==null) v = e.getValue(); - - b.put(k,v); + b.put(e.getKey().intern(), e.getValue().intern()); } - - record = PackedMap.of(b); + return PackedMap.of(b); } /** -- GitLab