Skip to content

Conversation

@joowon-byun
Copy link

@joowon-byun joowon-byun commented Jan 11, 2021

prque can have generic type. It could be used for []byte, time.Duration or other types if it is defined in Swap.
(PR from klaytn : klaytn/klaytn#840)

Comment on lines 131 to 134
if invert {
return !result
}
return result
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be harder on the eyes, but you could just xor result with invert and return that, sth like return invert ^ result. However, there's no xor operator for booleans, so it would instead be something lke return result != invert

// New creates a new priority queue.
func New(setIndex SetIndexCallback) *Prque {
return &Prque{newSstack(setIndex)}
func New(invert bool, setIndex SetIndexCallback) *Prque {
Copy link
Contributor

Choose a reason for hiding this comment

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

If instead of New(invert bool, ...) you turned it into two functions: New and NewInverted, then the original signature could remain, and the changes wouldn't touch as much code. Plus it's IMO a bit unelegant when the calling code which uses the 'default' always have to pass in a false as the first argument

@karalabe
Copy link
Member

I'm in general against this PR. My hunch is that is significantly impacts performance. Would have been nice to keep the tests and benchmarks from the upstream repo instead of dropping them and only leaving the code here.

@karalabe
Copy link
Member

@karalabe
Copy link
Member

I've opened a PR to pull the tests and benchmarks in too: #22157

Please provide a diff as to how your change behaves on the benchmark vs the old code.

@joowon-byun
Copy link
Author

@karalabe As you said, the benchmark shows a big degradation. I will close this PR.

BenchmarkPush-12    	 8966427	       115 ns/op
BenchmarkPush-12    	 7030219	       155 ns/op
BenchmarkPop-12    	 1000000	      1430 ns/op
BenchmarkPop-12    	 1000000	      2328 ns/op

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