Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pointer): better performance through directly managed pointers #8

Merged
merged 1 commit into from
May 7, 2020

Conversation

Arqu
Copy link
Contributor

@Arqu Arqu commented Apr 29, 2020

Pre-requisite for qri-io/jsonschema#65

@Arqu Arqu requested a review from b5 April 29, 2020 20:29
@Arqu Arqu added this to In progress in Sprint I via automation Apr 29, 2020
@Arqu Arqu self-assigned this Apr 29, 2020
@Arqu Arqu added the enhancement New feature or request label Apr 29, 2020
@b5 b5 moved this from In progress to Needs Review in Sprint I Apr 30, 2020
Copy link
Member

@b5 b5 left a comment

Choose a reason for hiding this comment

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

This is even easier than it seems!

pointer.go Outdated
// NewPointer creates a Pointer with a pre-allocated block of memory
// to avoid repeated slice expansions
func NewPointer() Pointer {
return make([]string, 0, 32)
Copy link
Member

Choose a reason for hiding this comment

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

32 should be made into a constant. Something like defaultPointerCap.

pointer.go Outdated
Comment on lines 119 to 141
// RawDescendant extends the pointer with 1 or more path tokens
// The function itself is unsafe but allows for much faster pointer management
func (p Pointer) RawDescendant(path ...string) (Pointer, error) {
return append(p, path...), nil
}

Copy link
Member

Choose a reason for hiding this comment

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

This isn't unsafe 😄! If the concern is potentially exceeding the cap, the go runtime will just re-allocate to a new pointer once the cap is exceeded:

https://stackoverflow.com/a/41668362

To that end, what about just calling this Descendant, or NewDescendant, and dropping the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, the "unsafe" part was more aimed at we don't completely re-parse the pointer and deal with the ecape/unescape dance.

@Arqu Arqu requested a review from b5 April 30, 2020 22:34
Sprint I automation moved this from Needs Review to Reviewer approved May 6, 2020
Copy link
Member

@b5 b5 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@b5 b5 left a comment

Choose a reason for hiding this comment

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

Totally cool with the API changes, just need to confirm that the change in the behaviour of String is something we want

pointer.go Outdated
Comment on lines 98 to 100
if len(str) == 0 {
str = "/"
}
Copy link
Member

Choose a reason for hiding this comment

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

Are we sure this matches the spec? I'm seeing two new test failures with this change. It may be that the tests are wrong.

=== RUN   TestParse
    TestParse: pointer_test.go:72: case 3 error mismatch. expected: 'parse ://: missing protocol scheme', got: 'parse "://": missing protocol scheme'
    TestParse: pointer_test.go:77: case 5 string output mismatch: expected: '', got: '/'
    TestParse: pointer_test.go:77: case 6 string output mismatch: expected: '', got: '/'

But these two used to return the empty string. The failure in test case three is also present on master, and comes from bumping up go versions

@Arqu Arqu merged commit c51da06 into master May 7, 2020
Sprint I automation moved this from Reviewer approved to Done May 7, 2020
@Arqu Arqu deleted the pointer-performance branch May 7, 2020 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Sprint I
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants