Skip to content

perf: count a guild's nodes once per upkeep total - #29

Merged
XxFran10xX merged 3 commits into
mainfrom
perf/upkeep-count
Oct 28, 2026
Merged

XxFran10xX merged 3 commits into
mainfrom
perf/upkeep-count

Conversation

@XxFran10xX

Copy link
Copy Markdown
Contributor

Why

NodeManager.getTotalUpkeep(g) asked every node of g for its daily upkeep. Each node worked out its cost increase by counting g's nodes, which walks every node and resolves its guild, so a guild total cost nodes × nodes guild lookups. It runs whenever a ledger reads node upkeep: SimpleFactions income, and the 5-minute chronicle export on Main (10-28 spark profile zZVrBKel7T).

Change

  • getTotalUpkeep passes a memoised count to the new Node.getDailyUpkeep(IntSupplier). The guild's nodes are counted at most once, and only when a node first needs the count.
  • getDailyUpkeep(IntSupplier) follows getDailyUpkeep() step for step, so results, rounding and exceptions are the same:
    • base upkeep first;
    • then the guild (an unresolved guild uses the stored cost increase, as before);
    • then the count;
    • then capacity.
  • getDailyUpkeep() is unchanged for single-node callers. The two share baseUpkeep(), dailyUpkeep(..) and storedCostIncrease().

Testing

  • NodeUpkeepTest passes unchanged.
  • NodeBehaviorTest checks on real nodes that getDailyUpkeep() equals getDailyUpkeep(() -> count), plus a counted value.
  • The full local build has only the 8 Windows-only failures that also fail on main (DatabaseTest, NodePaymentsTest); the changed lines are covered.
  • Reviewed by Sol (GPT-6.1) over three rounds:
    • round 1 approved the first version;
    • the full build then caught an eager count and the unresolved-guild fallback, which I fixed;
    • round 2 asked to keep the old base-first evaluation order, which I fixed;
    • round 3 approved.

🤖 Generated with Claude Code

XxFran10xX and others added 3 commits October 28, 2026 16:12
NodeManager.getTotalUpkeep(g) asked every node of g for its daily
upkeep, and each node worked out its cost increase by counting g's nodes
through a walk of every node: another nodes x nodes guild lookup, run
whenever a ledger reads node upkeep (SimpleFactions income and the
5-minute chronicle export on Main).

getTotalUpkeep now counts g's nodes once and passes the count to the new
Node.getDailyUpkeep(int), which uses the same cost formula. Every node it
adds belongs to g, so the count is the one each node would have found.
getDailyUpkeep() keeps working on its own for single-node callers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The full build caught NodeUpkeepTest: getTotalUpkeep counted g's nodes
before the loop, even when no node of g needed the count, and
getDailyUpkeep(int) always used the counted cost increase. The old
per-node path used the node's stored cost increase when its guild does
not resolve and only counted for nodes that reached it.

Node.getDailyUpkeep(IntSupplier) now falls back to getDailyUpkeep() when
the guild does not resolve, and getTotalUpkeep passes a memoised count
that walks the nodes at most once, on first use. NodeUpkeepTest passes
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sol review: the counted upkeep evaluated the node count before turning
the base upkeep into a BigDecimal, so a bad upkeep value (NaN) with a
failing count would surface a different exception than before. Both
upkeep methods now take the base first, then resolve the guild, then
count, which is the old order, and the unresolved fallback uses the
stored cost increase directly so the guild is resolved once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@XxFran10xX

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 624534cf-1069-4da5-bdcd-8c422754a2bd
Commits

Reviewing files that changed from the base of the PR and between 35f0c1f and 89cf740.

Files selected for processing: 4
  • src/main/java/net/tfminecraft/dowsing/managers/NodeManager.java
  • src/main/java/net/tfminecraft/dowsing/objects/Node.java
  • src/test/java/net/tfminecraft/dowsing/managers/NodeManagerCyclesTest.java
  • src/test/java/net/tfminecraft/dowsing/objects/NodeBehaviorTest.java
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the size:M 30-99 effective changed lines (tests excluded in mixed PRs). label Oct 28, 2026
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@XxFran10xX

Copy link
Copy Markdown
Contributor Author

CodeRabbit is rate limited; Sol (GPT-6.1) approved after three rounds (final: 89cf740, no findings; exact evaluation order and exceptions preserved). CI green. Merging.

@XxFran10xX
XxFran10xX merged commit d592390 into main Oct 28, 2026
3 checks passed
@XxFran10xX
XxFran10xX deleted the perf/upkeep-count branch October 28, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 effective changed lines (tests excluded in mixed PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant