-
Notifications
You must be signed in to change notification settings - Fork 105
Add Reader.LookupOffset & Decode #23
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
Conversation
case reflect.Uintptr: | ||
result.Set(reflect.ValueOf(uintptr(pointer))) | ||
return newOffset, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change necessary? Wouldn't the same thing happen in the call to .decode()
anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is de-referencing the pointer at offset
and storing the result, whereas the case in decode
is storing the referenced pointer prior to decode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add comments here & above to clarify the difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but then it calls decode
on the new offset from the pointer, which would do the Uintptr
handling for the new offset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, quite right. Updated to remove.
Overall this seems reasonable. I am a bit concerned with people not understanding the functionality and filing bug reports due to misuse. It also seems to add a small amount of overhead in the benchmarks, but that might be unavoidable. Longer term, I would like to implement some sort of caching strategy, although that might make more sense in a higher-level library like |
Expose database offsets, and decoding records at those offsets, as a first-class concept via LookupOffset & Decode. Allow decoded records to indirect nested structures by introducing special handling for the uintptr type: fields with this type are decoded by storing the database offset of the indirected record. Reflection is expensive, many database records ("continent", "country", etc) are embarrassingly cacheable, and database offsets make for excellent caching keys. These methods allow clients to trivially identify and re-use structures which have previously been extracted.
I've refactored and extended documentation on LookupOffset & Decode to document the behavior & the motivating use case. Let me know your thoughts.
Here's what I'm seeing now:
Agreed, I don't think that's appropriate in |
Looks great. Thanks! 👍 |
Expose database offsets, and decoding records at those offsets, as a
first-class concept via LookupOffset & Decode. Allow decoded records to
indirect nested structures by introducing special handling for the
uintptr type: fields with this type are decoded by storing the database
offset of the indirected record.
Reflection is expensive, many database records ("continent", "country", etc)
are embarrassingly cacheable, and database offsets make for excellent caching
keys. These methods allow clients to trivially identify and re-use structures
which have previously been extracted.
This change is