Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As I was writing this comment, I realized that the current state of finding/creating/dispatching NodeStats is sorta ridiculous. So I decided to improve things.
StatDispatcher
and its descendants), creates two functions instead (stats.dispatch_stat
andstats.dispatch_many_stats
).IDView
classes no longer need to create and hold reference to a dispatcher object.IDView
classes now need to hold a reference to the network itself, in the newly created instance variable_net
.The improvement is clear from the following benchmark. Note that this is measuring the time it takes to access
H.nodes.degree
on an empty network.Before:
After this PR:
This is a 3x improvement in the time it takes to access an attribute!.
Technical note: the way that things used to work is that a
NodeView
object would create and hold reference to aNodeStatDispatcher
object. Then, whenever aNodeStat
was requested, say by executingH.nodes.degree
, theNodeView
would rely on theNodeStatDispatcher
to find and create the correspondingNodeStat
object. After this PR, this is no longer the case, andNodeStat
just calls thedispatch_stat
function instead. No need for middle-men dispatcher classes!