Introduce a cache to improve performance of construction of SDFormat#1610
Introduce a cache to improve performance of construction of SDFormat#1610
Conversation
e3328a2 to
69c70c1
Compare
This commit should reduce load times significantly as it caches the first parse of the spec
so that it does not need to be reparsed at library load time through static initiallization of a pass.
On my m4 macbook air this reduces the following benchmark:
void deserialize()
{
std::string sdf = "<?xml version=\"1.0\" ?><sdf version='1.6'></sdf>";
sdf::Root root;
sdf::Errors errors = root.LoadSdfString(sdf);
if (!root.Model())
{
return;
}
sdf::Model _model = *root.Model();
return;
}
int main(int argc, char **argv)
{
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
for (int i = 0; i < 100; i++)
deserialize();
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
std::cout << "Whole function call took: " <<
std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count()
<< "[µs]" << std::endl;
}
from running for 300000µs to 3000µs.
Signed-off-by: Arjo Chakravarty <arjo@openrobotics.org>
69c70c1 to
60107a5
Compare
iche033
left a comment
There was a problem hiding this comment.
nice, this should replace gazebosim/gz-sim#3082
- Add copy constructor unit tests - Add doxygen comments Signed-off-by: Arjo Chakravarty <arjo@openrobotics.org>
|
Before I merge this, I think its worth pointing out that I think this breaks ABI (thanks to adding a copy constructor), in which case I should re-target this to main and we release these improvements in Kura. I am not 100% sure. According to KDE's guidelines adding new constructors is non-ABI breaking, however imo adding a copy constructor after-the fact may break ABI as the compilers might assume default copy for older versions. I think if someone can enlighten me as to whether my suspicion is right or wrong, I will retarget this PR accordingly. |
|
That's a great speed up!! Thanks for looking into it. We already do something like this in Lines 1741 to 1751 in 9c1bd31 So the approach is sound.
I don't think it breaks ABI because the compiler generates the copy constructor inside the shared library. From the binary symbol perspective, defining a new copy constructor here just means we're changing the behavior of the existing copy constructor. You can see the generated code on godbolt by commenting out the custom copy constructor: https://godbolt.org/z/4cjddMeTd |
Signed-off-by: Arjo Chakravarty <arjo@openrobotics.org>
|
Thanks for the clarification! I've resorted to using |
Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org> Signed-off-by: Arjo Chakravarty <arjo129@gmail.com>
Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org> Signed-off-by: Arjo Chakravarty <arjo129@gmail.com>
|
@Mergifyio backport main sdf15 sdf14 sdf12 |
✅ Backports have been createdDetails
|
…1610) Reduces load times significantly as it caches the first parse of the spec so that it does not need to be reparsed during construction through static initiallization of a cache. --------- Signed-off-by: Arjo Chakravarty <arjo@openrobotics.org> Signed-off-by: Arjo Chakravarty <arjo129@gmail.com> Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org> (cherry picked from commit 403d96a)
…1610) Reduces load times significantly as it caches the first parse of the spec so that it does not need to be reparsed during construction through static initiallization of a cache. --------- Signed-off-by: Arjo Chakravarty <arjo@openrobotics.org> Signed-off-by: Arjo Chakravarty <arjo129@gmail.com> Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org> (cherry picked from commit 403d96a)
…1610) Reduces load times significantly as it caches the first parse of the spec so that it does not need to be reparsed during construction through static initiallization of a cache. --------- Signed-off-by: Arjo Chakravarty <arjo@openrobotics.org> Signed-off-by: Arjo Chakravarty <arjo129@gmail.com> Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org> (cherry picked from commit 403d96a)
…1610) Reduces load times significantly as it caches the first parse of the spec so that it does not need to be reparsed during construction through static initiallization of a cache. --------- Signed-off-by: Arjo Chakravarty <arjo@openrobotics.org> Signed-off-by: Arjo Chakravarty <arjo129@gmail.com> Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org> (cherry picked from commit 403d96a) # Conflicts: # src/SDF_TEST.cc
…1610) Reduces load times significantly as it caches the first parse of the spec so that it does not need to be reparsed during construction through static initiallization of a cache. --------- Signed-off-by: Arjo Chakravarty <arjo@openrobotics.org> Signed-off-by: Arjo Chakravarty <arjo129@gmail.com> Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org> (cherry picked from commit 403d96a)
…1610) Reduces load times significantly as it caches the first parse of the spec so that it does not need to be reparsed during construction through static initiallization of a cache. --------- Signed-off-by: Arjo Chakravarty <arjo@openrobotics.org> Signed-off-by: Arjo Chakravarty <arjo129@gmail.com> Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org> (cherry picked from commit 403d96a)
…1610) Reduces load times significantly as it caches the first parse of the spec so that it does not need to be reparsed during construction through static initiallization of a cache. --------- Signed-off-by: Arjo Chakravarty <arjo@openrobotics.org> Signed-off-by: Arjo Chakravarty <arjo129@gmail.com> Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org> (cherry picked from commit 403d96a)
…1610) Reduces load times significantly as it caches the first parse of the spec so that it does not need to be reparsed during construction through static initiallization of a cache. --------- Signed-off-by: Arjo Chakravarty <arjo@openrobotics.org> Signed-off-by: Arjo Chakravarty <arjo129@gmail.com> Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org> (cherry picked from commit 403d96a) # Conflicts: # src/SDF_TEST.cc
🦟 Bug fix
Fixes #1478
Summary
This commit should reduce load times significantly as it caches the first parse of the spec so that it does not need to be reparsed during construction through static initiallization of a cache.
On my m4 macbook air this reduces the following benchmark:
from running for 300000µs to 3000µs.
Checklist
codecheckpassed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-byandGenerated-bymessages.