Skip to content

Conversation

@bertm
Copy link
Contributor

@bertm bertm commented May 13, 2025

All the Hashtables can easily be replaced by ConcurrentHashMap. This reduces potential lock contention (see also #989 for related work) in the node stats reporting, and simplifies the code by using modern constructs like computeIfAbsent and factoring out common code.

bertm added 2 commits May 13, 2025 18:01
Additionally, deduplicate the implementations for all the different
kinds of backoff.
Reuse the existing implementation for obtaining the TimedStats.
Comment on lines +3614 to +3619
List<TimedStats> stats = new ArrayList<>();
averages.forEach((key, avg) -> stats.add(
new TimedStats(key, avg.countReports(), (long) avg.currentValue(), (long) avg.totalValue())
));
Collections.sort(stats);
return stats.toArray(new TimedStats[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can I make a suggestion?

Suggested change
List<TimedStats> stats = new ArrayList<>();
averages.forEach((key, avg) -> stats.add(
new TimedStats(key, avg.countReports(), (long) avg.currentValue(), (long) avg.totalValue())
));
Collections.sort(stats);
return stats.toArray(new TimedStats[0]);
return averages.entrySet().stream()
.map(entry -> new TimedStats(entry.getKey(), entry.getValue().countReports(), (long) entry.getValue().currentValue(), (long) entry.getValue().totalValue()))
.sorted()
.toArray(TimedStats[]::new);

I just ❤️ the goddamn Streams API so much. 😄

@ArneBab ArneBab merged commit 72fd8c0 into hyphanet:next Jun 22, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants