Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.

perf: replace O(V*d) edge counting with O(E) single-pass - #110

Closed
sauravbhattacharya001 wants to merge 2 commits into
masterfrom
perf/count-edges-in-subgraph
Closed

sauravbhattacharya001 wants to merge 2 commits into
masterfrom
perf/count-edges-in-subgraph

Conversation

@sauravbhattacharya001

Copy link
Copy Markdown
Owner

Performance

\GraphUtils.countEdgesInSubgraph()\ previously iterated each vertex's incident edges and used a \HashSet\ to deduplicate — O(Σdeg) time + O(E_sub) memory for the seen set.

Change

Single pass over \graph.getEdges()\ checking endpoint membership in the vertex set (O(1) HashSet lookups). Eliminates the deduplication set and \getEndpoints()\ overhead entirely.

This method is called by \cycleRankOfSubgraph()\ and various analyzers, so the improvement cascades.

… in Network.java

The generateFile method had 5 nearly identical query execution blocks
(friends, study-groups, classmates, strangers, familiar-strangers) that
differed only in SQL template, edge label, and threshold values.

Changes:
- Extract LOCATION_MATCH_TEMPLATE and LOCATION_EXCLUDE_TEMPLATE as shared
  SQL templates with operator placeholders
- Add executeLocationMatchQuery() for parameterized location queries
- Add executeEdgeQuery() for location-exclusion queries
- Parameterize the location value (was previously hardcoded in SQL strings)
- Improve Javadoc and parameter naming conventions
countEdgesInSubgraph previously iterated each vertex's incident edges
and used a HashSet<edge> to deduplicate, resulting in O(Σdeg) time
plus O(E_sub) memory for the seen set and getEndpoints() overhead.

New implementation iterates graph.getEdges() once and checks endpoint
membership in the vertex set (O(1) HashSet lookups), eliminating the
deduplication set entirely. This is both faster and allocates less.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions github-actions Bot added visualization Graph visualization and UI database Database queries and schema size/l labels Mar 22, 2026
@sauravbhattacharya001

Copy link
Copy Markdown
Owner Author

Closing: superseded or conflicting with newer changes already on main/master.

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

Labels

database Database queries and schema size/l visualization Graph visualization and UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant