Closed halfgaar closed 1 year ago
@halfgaar, how shall we approach this one. I remember you mentioned that the payload should be exposed in the plugin_alter
functions too. But does it have to be readonly or modifiable?
My plan was to (try to) implement the read-only option. It mostly means stopping support for Ubuntu 18. I've been kind of sluggish, I know. But the time is about now to do it.
I have updated my draft PR to include the payload in the two F_flashmq_plugin_alter_XX functions. As with the previous commit it compiles but I haven't tested it. These are breaking changes and I think your idea was to create plugin version 2 which will require more work to support many versions. If I can help with something - let me know.
My next few weeks are busy, but I did perform a quick upgrade of my PC here so I have C++ 17 available. I'll probably have some time to dive into this soon.
What needs testing (+test code) is whether the payload is visible in the plugin for:
$SYS
)I created a branch with a draft. I didn't actually test much manually, but all automated tests do assert that the payload is not empty, so it should work. I'll check in more detail later.
The current implementation doesn't work and needs some small changes. I am in the middle of testing and will push a commit in my branch later today.
Note that my implementation works very differently from yours. You may want to make a new branch.
I had a look at your branch. The modifications I had to do in mine to make it work are coming closer to yours, although yours look more logical (you know your code better than anyone else :+1: ). I will stop updating my branch for now. Only one thing you may want to consider - std::string_view is really cheap to be passed by value and will perform better than passing by const ref)
Only one thing you may want to consider - std::string_view is really cheap to be passed by value and will perform better than passing by const ref)
Can you elaborate on that? I thought that was only true for plain old data types. It would seem to be a simple 64 bit value as address is cheaper. Only if you benefit from locality of reference and/or CPU cache would a copy seem faster to me, but with a string_view
, that's not possible anyway (it will most likely point far).
Using a reference has the advantage of being faster when you don't use the payload.
I tried to compare with Godbolt compiler explorer, but my test code was too synthetic and the optimizer threw it all away anyway...
I don't have personal experience measuring performance, it is all I have read. But when you google it you will read everywhere that std::string_view
is faster to pass by value - it has only two members which fit well into the CPU registers, while with the reference you have one more indirection. Here are some links:
std::string_view
by value - https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelinesInteresting. I'll dive into more and likely make it a copy by value then.
Is the feature also working out for you? Having your approval before I merge it in would be great.
Yes, the payload is now available in the plugin. Thanks.
Is it weird that for an empty payload, we point it to outside the vector bites
with a length 0 ... ?
It is an interesting one. I think it should be fine. std::string_view
is not a zero based c-type string, it always relies on the length to be setup correctly. So with a length of 0 it should be considered empty, no matter what the data points to.
Released.
Review + test + think about https://github.com/slavslavov/FlashMQ/pull/1.
Was discussed here.