View Issue Details

IDProjectCategoryView StatusLast Update
0023850Open CASCADEOCCT:Application Frameworkpublic2015-07-27 15:01
Reportervro Assigned Tovro  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
PlatformWindowsOSVC++ 2010 
Product Version6.5.3 
Target Version6.7.0Fixed in Version6.7.0 
Summary0023850: TDataStd_ByteArray is too slow on storage on disk
DescriptionIf a TDataStd_ByteArray contains several hundreds of thousands of values, it takes a minute to store the array on disk using any of OCAF storage mechanisms.
Steps To Reproduce#Create an OCAF document. Use XML as a test storage schema.
NewDoc D XmlOcaf
#Set a long byte array of many-many values. Here it is an array of 10 values (seems not enough for performance test).
SetByteArray D 0:1 0 1 10 1 2 3 4 5 6 7 8 9 10
# Save the document on disk and measure time of storage.
SaveAs D test.xml
TagsNo tags attached.
Test case numbercaf bugs(006) D1

Attached Files

  • Test23850.zip (1,575 bytes)

Activities

vro

2013-03-22 13:06

developer   ~0023857

Dear Szy, could you please review the changes? A file XmlMDataStd_ByteArrayDriver.cxx is modified in CR23850.

vro

2013-04-12 16:18

developer   ~0024121

I modified the same file once again. Could you please review the changes?

vro

2013-04-26 11:39

developer   ~0024289

Storage of a TDataStd_TreeNode is accelerated. For a document, where a TDataStd_TreeNode has 100 000 children, storage is about 8 times faster now!
Don't review this improvement yet, please. I would like to continue... and rebase the changes at the end.

vro

2013-05-15 09:40

developer  

Test23850.zip (1,575 bytes)

vro

2013-05-15 09:57

developer   ~0024387

Dear Mpv,
Could you review the improvement, please?
The improvement consists of increase of speed of storage on disk for several Ocaf attributes: TreeNode, IntegerArray, IntegerList, ...
Also, I had to add several new draw-commands to manipulate with the Ocaf attributes: SetBooleanArray, GetBooleanArray, SetIntegerList, GetIntegerList, ...
A draw-script Test23850 (attached) sets the attributes for a document, saves the document on disk in XML format and then reads it back and checks saved values. This script might be used for non-regression tests of this improvement, I suppose.
The changes are in CR23850 branch.
Any questions are welcome,
Vro

abv

2013-05-15 10:07

manager   ~0024388

Vlad, could you add a test script to Git branch to make it directly usable (see http://files.opencascade.com/delivery/download/OCCT_Tests.pdf for how-to)?

vro

2013-05-15 12:12

developer   ~0024393

A test-script caf\bugs\D1 is added to control this improvement.

mpv

2013-05-15 17:06

developer   ~0024405

  Dear Vlad,

in files

XmlMDataStd_BooleanListDriver.cxx, XmlMDataStd_IntegerArrayDriver.cxx, XmlMDataStd_IntegerListDriver.cxx, XmlMDataStd_IntPackedMapDriver.cxx, XmlMDataStd_RealArrayDriver.cxx, XmlMDataStd_RealListDriver.cxx, XmlMDataStd_TreeNodeDriver.cxx

there must be "+1" in allocated size of the arrays to avoid possible memory problems (zero symbol in the end of string may be located out of range or array).

vro

2013-05-16 08:10

developer   ~0024408

Done! + 1 is added to keep '\0', thanks.

abv

2013-05-16 09:47

manager   ~0024410

Using direct calls to Standard::Allocate and Standard::Free for pointers to char is bad practice, please try to avoid this (consider using C++ classes, e.g. TCollection_AsciiString can be used as safe string buffer).

vro

2013-05-16 09:56

developer   ~0024411

Do you mean to use:
TCollection_AsciiString str("", length);
instead of:
Standard_Character* str = (Standard_Character*) Standard::Allocate(length + 1)?

In this case we don't need to free the string, the C++ class (TCollection_AsciiString) will do it for us. Do you mean that?

vro

2013-05-16 16:17

developer   ~0024421

I thought about your idea and it seems to me usage of TCollection_AsciiString is not reasonable here because:
1) It will hide calling of Standard_Free() for the array of chars. For some drivers, for example for the BooleanArrayDriver the array is allocated following a condition (inside an "IF" statement), which makes not obvious allocation and release of the array. So, it decreases the source code visibility.
2) It slows-down the drivers because of filling-in the allocated array by a "filler" character. It slows-down not very much, but I would prefer not to spend time at all.
3) TCollection_AsciiString returns a constant reference to the allocated array of characters (the method ToCString()). In order to use this array in the method sprintf() it is neccesary to cast the object to Standard_Character* (without a const specifier). It looks like a "hacking" code... which doesn't add visibility.
What do you think?

mpv

2013-05-16 17:48

developer   ~0024423

I agree with Vlad: "Cut" method of two AsciiString-s here is too slow, usage of "ToCString" for sprintf here is awful.
Perhaps, ideal solution here is creation of new container for array of characters (TCollection_Buffer?) for encapsulation of memory management and appending any type (char, int, real, etc) as string...

abv

2013-05-16 21:48

manager   ~0024426

Well, then consider using NCollection_Array1<char>. If you need optimization for small buffers, check PLib_LocalArray: this class can be made template (and moved to NCollection) to be useful for chars

vro

2013-05-21 08:35

developer   ~0024441

PLib_LocalArray is renamed to NCollection_LocalArray and became a template. It is used as a local array for Standard_Character in XML OCAF drivers, and as a local array of Standard_Real in PLib package.

Also, I forgot to mention this, sorry, I extended a RealDriver to support 17 digits after a decimal point (previously it used 15). Now it allows to store and retrieve a double value with highest precision.

The changes are in CR23850.

mpv

2013-05-21 08:54

developer   ~0024442

It seems it is OK and corresponds to notes now.

vro

2013-05-21 09:40

developer   ~0024443

Dear Mkv,
Integrate please the changes of CR23850.

vro

2013-05-21 09:51

developer   ~0024444

Please review it again.

vro

2013-05-21 12:14

developer   ~0024447

Information about improvement of performance. Speed of storage of an OCAF document in XML file format increased for about 10% (for an usual OCAF document with short arrays). For the documents using long arrays speed increased in about 10 times.

mkv

2013-05-22 17:52

tester   ~0024473

Dear BugMaster,

Branch CR23850 (and products from GIT master) was compiled on Linux and Windows platforms and tested.
SHA-1: 5744855b06828092584808c4ae1015b0a7265c7e

Number of compiler warnings:

occt component :
Linux: 2 (2 on master)
Windows: 11 (11 on master)

products component :
Linux: 0 (0 on master)
Windows: 64 (64 on master)

Regressions:
No regressions

Improvements:
No improvements

Testing cases:
caf bugs(006) D1 - OK.

Testing on Linux:
Total MEMORY difference: 365793192 / 365785356
Total CPU difference: 42342.64000000116 / 45769.360000001354

Testing on Windows:
Total MEMORY difference: 419285528 / 420608076
Total CPU difference: 30196.25 / 30692.265625

There are not differences in images found by testdiff.

git

2014-12-30 09:05

administrator   ~0035861

Branch CR23850 has been created by mpv.

SHA-1: 7b202085e63d83af2977f0543be5a5dcf56d227b


Detailed log of new commits:

Author: mkv
Date: Wed May 22 12:10:37 2013 +0400

    Small correction of test case for this fix

Author: vro
Date: Tue May 21 08:24:40 2013 +0400

    PLib_LocalArray is renamed to NCollection_LocalArray and became a template. It is used as a local array for Standard_Character in XML OCAF drivers, and as a local array of Standard_Real in PLib package.

Author: vro
Date: Thu May 16 15:43:22 2013 +0400

    Removed several spaces in source files.

Author: vro
Date: Thu May 16 08:08:53 2013 +0400

    + 1 is added to keep '\0'

Author: vro
Date: Wed May 15 12:10:10 2013 +0400

    A test-script for OCAF document successfully saved and opened from disk in XML file format.

Author: vro
Date: Wed May 15 09:49:28 2013 +0400

    Several draw-commands are added to manipulate the basic Ocaf attributes:
    BooleanArray
    BooleanList
    IntegerList
    RealList

Author: vro
Date: Tue May 14 14:08:58 2013 +0400

    Improvement of speed of storage of several Ocaf attributes in XML file format.
    Also, format of storage of a double value is extended to keep 17 digits after a decimal point (it was used only 15 digits before).

Author: vro
Date: Fri Apr 26 11:36:18 2013 +0400

    Same improvement for storage of a TDataStd_TreeNode.

Author: vro
Date: Fri Apr 12 16:16:19 2013 +0400

    A possible bug is corrected (size of an array is extended a little).

Author: vro
Date: Fri Mar 22 13:05:27 2013 +0400

    Optimization of a byte-array for XML persistence (binary persistence is ok).

git

2015-07-27 15:01

administrator   ~0043581

Branch CR23850 has been deleted by kgv.

SHA-1: 7b202085e63d83af2977f0543be5a5dcf56d227b

Related Changesets

occt: master f7b4312f

2013-05-23 08:09:09

vro

Details Diff
0023850: TDataStd_ByteArray is too slow on storage on disk

Optimization of a byte-array for XML persistence (binary persistence is ok).
A possible bug is corrected (size of an array is extended a little).
Same improvement for storage of a TDataStd_TreeNode.
Improvement of speed of storage of several Ocaf attributes in XML file format.
Also, format of storage of a double value is extended to keep 17 digits after a decimal point (it was used only 15 digits before).
Several draw-commands are added to manipulate the basic Ocaf attributes:
BooleanArray
BooleanList
IntegerList
RealList
A test-script for OCAF document successfully saved and opened from disk in XML file format.
+ 1 is added to keep '\0'
Removed several spaces in source files.
PLib_LocalArray is renamed to NCollection_LocalArray and became a template. It is used as a local array for Standard_Character in XML OCAF drivers, and as a local array of Standard_Real in PLib package.
Small correction of test case for this fix
Affected Issues
0023850
mod - src/BSplCLib/BSplCLib.cxx Diff File
mod - src/BSplSLib/BSplSLib.cxx Diff File
mod - src/DDataStd/DDataStd_BasicCommands.cxx Diff File
mod - src/NCollection/FILES Diff File
mod - src/PLib/FILES Diff File
mod - src/PLib/PLib.cxx Diff File
mod - src/PLib/PLib_HermitJacobi.cxx Diff File
mod - src/XmlMDataStd/XmlMDataStd_BooleanArrayDriver.cxx Diff File
mod - src/XmlMDataStd/XmlMDataStd_BooleanListDriver.cxx Diff File
mod - src/XmlMDataStd/XmlMDataStd_ByteArrayDriver.cxx Diff File
mod - src/XmlMDataStd/XmlMDataStd_IntegerArrayDriver.cxx Diff File
mod - src/XmlMDataStd/XmlMDataStd_IntegerListDriver.cxx Diff File
mod - src/XmlMDataStd/XmlMDataStd_IntPackedMapDriver.cxx Diff File
mod - src/XmlMDataStd/XmlMDataStd_RealArrayDriver.cxx Diff File
mod - src/XmlMDataStd/XmlMDataStd_RealDriver.cxx Diff File
mod - src/XmlMDataStd/XmlMDataStd_RealListDriver.cxx Diff File
mod - src/XmlMDataStd/XmlMDataStd_TreeNodeDriver.cxx Diff File
add - tests/caf/bugs/D1 Diff File

Issue History

Date Modified Username Field Change
2013-03-22 12:58 vro New Issue
2013-03-22 12:58 vro Assigned To => vro
2013-03-22 13:06 vro Note Added: 0023857
2013-03-22 13:06 vro Assigned To vro => szy
2013-03-22 13:06 vro Status new => resolved
2013-04-12 16:18 vro Note Added: 0024121
2013-04-12 16:18 vro Assigned To szy => abv
2013-04-12 16:18 vro Status resolved => assigned
2013-04-26 11:39 vro Note Added: 0024289
2013-04-26 11:39 vro Assigned To abv => vro
2013-05-15 09:40 vro File Added: Test23850.zip
2013-05-15 09:57 vro Note Added: 0024387
2013-05-15 09:57 vro Assigned To vro => mpv
2013-05-15 09:57 vro Status assigned => resolved
2013-05-15 10:07 abv Note Added: 0024388
2013-05-15 12:12 vro Note Added: 0024393
2013-05-15 17:06 mpv Note Added: 0024405
2013-05-15 17:06 mpv Assigned To mpv => vro
2013-05-15 17:06 mpv Status resolved => assigned
2013-05-16 08:10 vro Note Added: 0024408
2013-05-16 08:10 vro Assigned To vro => mpv
2013-05-16 08:10 vro Status assigned => resolved
2013-05-16 09:47 abv Note Added: 0024410
2013-05-16 09:56 vro Note Added: 0024411
2013-05-16 16:17 vro Note Added: 0024421
2013-05-16 17:48 mpv Note Added: 0024423
2013-05-16 21:48 abv Note Added: 0024426
2013-05-21 08:35 vro Note Added: 0024441
2013-05-21 08:54 mpv Note Added: 0024442
2013-05-21 08:54 mpv Status resolved => reviewed
2013-05-21 09:40 vro Note Added: 0024443
2013-05-21 09:40 vro Assigned To mpv => mkv
2013-05-21 09:40 vro Status reviewed => assigned
2013-05-21 09:51 vro Note Added: 0024444
2013-05-21 09:51 vro Assigned To mkv => mpv
2013-05-21 09:51 vro Status assigned => resolved
2013-05-21 09:54 mpv Status resolved => reviewed
2013-05-21 10:33 mkv Assigned To mpv => mkv
2013-05-21 12:14 vro Note Added: 0024447
2013-05-22 17:52 mkv Note Added: 0024473
2013-05-22 17:53 mkv Test case number => caf bugs(006) D1
2013-05-22 17:53 mkv Assigned To mkv => bugmaster
2013-05-22 17:53 mkv Status reviewed => tested
2013-05-23 12:40 bugmaster Target Version Unscheduled => 6.7.0
2013-05-24 13:06 vro Changeset attached => occt master f7b4312f
2013-05-24 13:06 vro Assigned To bugmaster => vro
2013-05-24 13:06 vro Status tested => verified
2013-05-24 13:06 vro Resolution open => fixed
2013-12-19 13:53 bugmaster Status verified => closed
2013-12-19 13:55 bugmaster Fixed in Version => 6.7.0
2014-12-30 09:05 git Note Added: 0035861
2015-07-27 15:01 git Note Added: 0043581