From efe3b701c08041b6080e9ca6517d1e876e0d05f7 Mon Sep 17 00:00:00 2001 From: Saurav Bhattacharya Date: Wed, 18 Mar 2026 00:44:13 -0700 Subject: [PATCH] perf: use double instead of float for edge weights The edge weight field was stored as float but every algorithm (Dijkstra, Louvain, ForceDirected, PageRank, etc.) operates on doubles internally. This caused implicit float-to-double widening on every getWeight() call in hot loops. Changes: - edge.java: weight field float -> double, getter/setter updated - GraphFileParser: Float.parseFloat -> Double.parseDouble for precision and to avoid widening on store - All existing float literal callers auto-widen safely (no source changes needed) --- Gvisual/src/gvisual/GraphFileParser.java | 6 +++--- Gvisual/src/gvisual/edge.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Gvisual/src/gvisual/GraphFileParser.java b/Gvisual/src/gvisual/GraphFileParser.java index 3138641..a87f36a 100644 --- a/Gvisual/src/gvisual/GraphFileParser.java +++ b/Gvisual/src/gvisual/GraphFileParser.java @@ -136,15 +136,15 @@ public static ParseResult parse(String filePath, Predicate visibleFilter continue; } - float weight; + double weight; try { - weight = Float.parseFloat(parts[3]); + weight = Double.parseDouble(parts[3]); } catch (NumberFormatException e) { LOGGER.warning("Skipping edge with invalid weight: " + line); skipped++; continue; } - if (Float.isNaN(weight) || Float.isInfinite(weight)) { + if (Double.isNaN(weight) || Double.isInfinite(weight)) { LOGGER.warning("Skipping edge with non-finite weight: " + line); skipped++; continue; diff --git a/Gvisual/src/gvisual/edge.java b/Gvisual/src/gvisual/edge.java index bb1b6a4..c746838 100644 --- a/Gvisual/src/gvisual/edge.java +++ b/Gvisual/src/gvisual/edge.java @@ -12,7 +12,7 @@ public class edge { private String edgeType; private String vertex1; private String vertex2; - private float weight; + private double weight; private String label; private Long timestamp; // epoch millis (null = static/untimed edge) private Long endTimestamp; // optional: for interval-based edges @@ -63,12 +63,12 @@ public edge(String edgeType,String vertex1,String vertex2) this.vertex2 = vertex2; } - public void setWeight(float weight) + public void setWeight(double weight) { this.weight = weight; } - public float getWeight() + public double getWeight() { return this.weight; }