Skip to content

Faster default/copy construction of TObjects #482

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

Merged
merged 1 commit into from
Apr 6, 2017

Conversation

sawenzel
Copy link
Contributor

@sawenzel sawenzel commented Apr 6, 2017

  • This commit allows the compiler to potentially
    inline/optimize construction of TObjects
  • This is in particular important for data-objects
    which are created billions of times and which inherit from
    TObject

@phsft-bot
Copy link

Can one of the admins verify this patch?

@sawenzel
Copy link
Contributor Author

sawenzel commented Apr 6, 2017

complimentary info:

For this test program

#include "TObject.h"

class Track : public TObject {
public:
  Track() : TObject() {}
  virtual ~Track() = default;

private:
  double x=0.;
  double y=0.;
  double z=0.;
};

// noinline for valgrind purposes
__attribute__((noinline)) void createtracks(std::vector<Track> &v, int N) {
  for(int i=0;i<N;++i){
    v.emplace_back();
  }
}

int main() {
  // switch off object stat
  TObject::SetObjectStat(false);

  int N=1000000;
  std::vector<Track> tracks;
  tracks.reserve(N);

  createtracks(tracks, N);
  return 0;
}

the patch decreases the CPU cycle count for the function createtracks from 28billion to 21billion.
The patch is inspired from measurements in our digitization procedure which creates lots of such objects.

@sawenzel
Copy link
Contributor Author

sawenzel commented Apr 6, 2017

@Axel-Naumann : see complimentary info. The compiler voluntarily inlines this.

@Axel-Naumann
Copy link
Member

@phsft-bot build!

Copy link
Member

@Axel-Naumann Axel-Naumann left a comment

Choose a reason for hiding this comment

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

pending Jenkins.

@Axel-Naumann Axel-Naumann requested a review from pcanal April 6, 2017 08:17
@phsft-bot
Copy link

Starting build on centos7/gcc49, mac1011/native, slc6/gcc49, slc6/gcc62, ubuntu14/native and CMake flags -Dccache=ON -Dimt=OFF

@vgvassilev
Copy link
Member

@sawenzel, cool. Could you wait to merge the gtest PR #451, and convert the example program into a unit test?


fUniqueID = 0;

if (fgObjectStat) TObject::AddToTObjectTable(this);
Copy link
Member

Choose a reason for hiding this comment

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

For an additional performance boost, try,

if (R__unlikely(fgObjectStat)) TObject::AddToTObjectTable(this);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do.... thanks for the suggestion

@@ -158,6 +139,11 @@ TObject::~TObject()
if (fgObjectStat && gObjectTable) gObjectTable->RemoveQuietly(this);
}

void TObject::AddToTObjectTable(TObject *op)
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a documentation/comment for this routine (et/or a raison d'etre)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can do. It is here because I could not use directly TObjectTable::AddObj because this would introduce a cyclic dependency of headers.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is the last missing piece (doc for functions is required per coding convention).

@pcanal
Copy link
Member

pcanal commented Apr 6, 2017

@vgvassilev "convert the example program into a unit test?"
This is a performance test and the gain is relative to without the inlining, how do you invision this applied into a (stable) unit test?

@pcanal
Copy link
Member

pcanal commented Apr 6, 2017

@sawenzel This is very nice thanks. For consistency's sake, shouldn't we also move the copy constructor and operator=?

Thanks.

@vgvassilev
Copy link
Member

Ok, I see, I got the impression this is more than moving a method inline. @sawenzel please ignore my request.

@sawenzel sawenzel force-pushed the swenzel/TObjectconstr branch from a63ad3e to 2d2b565 Compare April 6, 2017 13:24
@sawenzel
Copy link
Contributor Author

sawenzel commented Apr 6, 2017

@pcanal : Thanks for these suggestions. I made a new version.

@sawenzel sawenzel changed the title Faster default construction of TObjects Faster default/copy construction of TObjects Apr 6, 2017

inline TObject &TObject::operator=(const TObject &rhs)
{
if (this != &rhs) {
Copy link
Member

Choose a reason for hiding this comment

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

probably would also benefit from

if (R__likely(this != &rhs)) {

Cheers, Philippe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@sawenzel sawenzel force-pushed the swenzel/TObjectconstr branch from 2d2b565 to d6ac940 Compare April 6, 2017 14:01
@pcanal
Copy link
Member

pcanal commented Apr 6, 2017

@sawenzel Could you also add a (summarized) version of the 'complementary info' in the commit log and/or code-comments?
Thanks.

@sawenzel sawenzel force-pushed the swenzel/TObjectconstr branch from d6ac940 to 1810e10 Compare April 6, 2017 14:07
@sawenzel
Copy link
Contributor Author

sawenzel commented Apr 6, 2017

@pcanal : done

@sawenzel sawenzel force-pushed the swenzel/TObjectconstr branch 3 times, most recently from 61446d7 to da003dd Compare April 6, 2017 19:26
 * This commit allows the compiler to potentially
   inline/optimize construction of TObjects
 * This is in particular important for data-objects
   which are created billions of times and which inherit from
   TObject

The effects of these changes were shown to be visible in
a test study. Creation of a large amount of simple objects
deriving from TObject benefited from a ~30% speed improvement
(as measured by valgrind callgrind).
@pcanal pcanal merged commit 5a7f0a1 into root-project:master Apr 6, 2017
@dpiparo
Copy link
Member

dpiparo commented Apr 13, 2017

This PR breaks roottest-root-io-filemerger-make. The symptom is a different size of the TStreamerInfo record on disk. I am reverting the commit in order to stabilise the CI of ROOT. We need to further investigate why this apparently unrelated change has an effect given the very delicate area where the problem has been identified.

@sawenzel
Copy link
Contributor Author

Thanks for this information. Is there a timeline to investigate the issue?

@dpiparo
Copy link
Member

dpiparo commented Apr 25, 2017

Hi,

we plan to branch for 6.10 on May the 10th.

@sawenzel
Copy link
Contributor Author

Thanks Danilo.

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.

6 participants