Skip to content
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

C3DFileAdapter: very slow file reading to Tables #1698

Closed
nickbianco opened this issue May 8, 2017 · 7 comments
Closed

C3DFileAdapter: very slow file reading to Tables #1698

nickbianco opened this issue May 8, 2017 · 7 comments
Assignees
Milestone

Comments

@nickbianco
Copy link
Member

Reading a c3d file's data to a Table using the C3DFileAdapter is currently very slow. I compared loading a c3d file (1 minute of walking data) using @jimmyDunne's btk_loadc3d() MATLAB script to the C3DFileAdapter and got the following results after 3 runs (Windows 7, 64-bit, i5 2.50 GHz):

btk in MATLAB: 0.39 +/- 0.07 seconds
C3DFileAdapter: 671.96 +/- 20.08 seconds

If you'd like to recreate the test, I can send you the file I used.

import org.opensim.modeling.*

file = 'slk.c3d';

% Using btk directly in MATLAB (need btk MATLAB wrapper)
tic
data = btk_loadc3d(file);
disp('btk in MATLAB: ')
toc

disp(' ')
 
% Using new C3DFileAdapter in 4.0
tic
adapter = C3DFileAdapter();
tables = adapter.read(file);
disp('C3DFileAdapter: ')
toc
@jimmyDunne
Copy link
Member

Need to add a benchmark to the test case. Profile each step to see where issue is coming from.

@jimmyDunne jimmyDunne assigned aseth1 and unassigned jimmyDunne May 18, 2017
@jimmyDunne
Copy link
Member

@aseth1 will profile

@chrisdembia
Copy link
Member

I did some profiling and it seems that the issue is the resizing that DataTable_::appendRow() does (this takes up 66% of the time in testC3DFileAdapter). I tried to pre-allocate the matrix underneath the DataTable, but I was not successful. @aseth1 let me know if you want to chat about this.

@chrisdembia
Copy link
Member

Here's how I got the number of rows and column:

        int marker_num_frames = marker_pts->GetFrontItem()->GetFrameNumber();
        int marker_num_columns = marker_pts->GetItemNumber();
        marker_table.updMatrix().resize(marker_num_frames, marker_num_columns);

@aseth1
Copy link
Member

aseth1 commented May 24, 2017

Thanks @chrisdembia for checking and suggesting a fix. I can confirm your findings in VS2015 profiler:
87.1 % -> _depData.resizeKeep(_depData.nrow() + 1, _depData.ncol());

@chrisdembia
Copy link
Member

Ah; it seems like your profiler was more helpful. Let me know if you want to chat more.

@aymanhab
Copy link
Member

PR in review

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

No branches or pull requests

7 participants