h5cpp icon indicating copy to clipboard operation
h5cpp copied to clipboard

Speed up ObjectHandle.close()

Open jkotan opened this issue 4 years ago • 3 comments

One more think which can be speed-up is ObjectHandle.close() which is called quite often. It can be done by avoiding calls to H5Iget_type and storing the object type in the class instance variable. It is unlikely that the type of the object has been changed.

jkotan avatar Nov 04 '21 07:11 jkotan

Do you experience any performance issues due to this method?

eugenwintersberger avatar Nov 29 '21 18:11 eugenwintersberger

Hi Eugen, since PR #510, #511, #512, #514 and #515 limited a number of created objects so the number of ObjectHandle.close() executions dropped down and it is no more the serious issue. However, according to callgrind in the example test code

    vector<long int> vc(1);
    for(size_t i = 0; i < 100000; i++) {
      vc[0] = static_cast<long int>(std::rand());
      dataset.resize({i + 1});
      selection.offset(0, i);
      dataset.write(vc, selection);
    }

the close() method takes 9.9 % of time (executed ones for each loop step by file_space selection destructor). From that hdf5::ObjectHandle::get_type() takes more than 1/3 while H5Sclose takes ~ 2/3. Creating this ticket I wanted to point out where one can improve the speed. In the above case get_type() takes ~ 3% so it is not so serious anymore.

jkotan avatar Nov 30 '21 08:11 jkotan

ok. I see. This are about 10% of the overall runtime. You are absolutely right one should deal with this.

eugenwintersberger avatar Dec 15 '21 08:12 eugenwintersberger