Menu

#64 auto_buffer <...>::swap performance

1.9
open
nobody
performance (1)
5
2015-08-27
2015-06-16
magnimbe
No

When we have to swap two auto_buffer objects and both are currently using their internal buffers, the current implementation does the following:

tmp = rhs;
rhs = lhs;
lhs = tmp;

We can see that the values that used to be rhs are copied twice (once to tmp and once to lhs), while the values that used to be in lhs are only copied once (to rhs).

The following optimization would help when the objects are different in size:

if (lhs.size () < rhs.size ())
{
tmp = lhs;
lhs = rhs;
rhs = tmp;
}
else
{
tmp = rhs;
rhs = lhs;
lhs = tmp;
}

(I have used pseudocode above instead of real C++.)

Thank you ! (-:

Discussion

  • Matt Wilson

    Matt Wilson - 2015-08-26

    Just verified that this does indeed bring a performance bump - on the order of 20% in the scenarios I tested.

    Just got to do functional testing now, then it's in next release.

    Thanks

    Matt

     
    • magnimbe

      magnimbe - 2015-08-27

      On 8/26/15, Matt Wilson matsys@users.sf.net wrote:

      Just verified that this does indeed bring a performance bump - on the order
      of 20% in the scenarios I tested.

      Just got to do functional testing now, then it's in next release.

      Thanks

      Matt

      Dear Mr. Wilson,

      Thank you ! I was so happy today ! Thank you kindly for all your work
      (as in all-your-work-multiplied-by-all-our-compilers) ! >:D<

      Sincerely,
      Adder

       
  • Matt Wilson

    Matt Wilson - 2015-08-27

    You're most welcome.

    I'd be interested to hear what you're using STLSoft for.

     
    • magnimbe

      magnimbe - 2015-08-29

      On 8/27/15, Matt Wilson matsys@users.sf.net wrote:

      You're most welcome.

      I'd be interested to hear what you're using STLSoft for.

      Greetings again !

      I am currently working on a Windows GUI application, where I replaced
      fixed-size buffers on the stack (e.g. "TCHAR ac [MAX_PATH];") with
      vectors (i.e. "std::vector <TCHAR> vc (MAX_PATH);") and now, finally,
      with auto_buffer's.

      I am also trying to use at least a part of ATL with Digital Mars C++,
      because its linker is much faster than the one from
      Borland/Inprise/Borland/CodeGear/Embarcadero (which is much faster
      than the one from Microsoft). When the executable reaches 6 or 7 MB in
      size (and the TDS file exceeds 32 MB), linking with debug information
      takes 10 to 15 seconds.

      In that regard, I have encountered a few issues with ATL::CComPtr and
      even more with ATL::CComQIPtr -- especially issues related to Digital
      Mars not supporting the uuidof extension. I saw code that used
      traits to support
      uuidof in your library... For some reason, I
      copied and pasted it with the comment at the bottom of this email.

      Unrelated to STLSoft, I am working on a build system that will finally
      throw "make" into oblivion -- it is based on the concepts (not the
      language) of Boost.Build v2, with some extra goodies (like beautified
      command lines, batch compiling of multiple sources at once, ignoring
      features irrelevant for some targets/generators, etc.) and (most
      importantly) greatly improved speed.

      Also, I have been using your book ("Imperfect C++"). Its sections on
      ABI and Veneers greatly helped clarify many aspects of COM and ATL for
      me and I have been reading those sections in parallel with "Inside
      ATL" (and with the header files)...

      //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
      // GUID_Traits:
      //
      // This is an adaptation (read: "copy-paste")
      // of comstl::IID_traits in Matthew Wilson's STLSoft library.
      //
      // Dear Mr. Matthew Wilson, please forgive me for not also copy-pasting
      // the copyright material, in here or in any project using this library.
      // Thank you for your work and for your books
      // (should that be any comfort, bwahahahhahahahaa !)...
      //
      // Usage:
      //
      // Instead of writing __uuidof (I)
      // (where I is IUnknown or any interface name),
      // we write Adder::GUID_Traits <I>::iid
      // and we add this text (e.g. in an included header):
      // namespace Adder { ADDER_IID_TRAITS_DEFINE (I); }
      // (of course, not inside another namespace; Adder should refer to ::Adder).
      //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

      Regarding auto_buffer specifically, I think it will prove even more
      useful when trying to make a little mobile app...

      Have a great day !

      --
      Yours truly,
      Adder

       

Log in to post a comment.