Skip to content

PERF Only call malloc twice in liblinear to_sparse helpers#14170

Merged
jeremiedbb merged 1 commit intoscikit-learn:masterfrom
alexhenrie:prealloc
Jul 5, 2019
Merged

PERF Only call malloc twice in liblinear to_sparse helpers#14170
jeremiedbb merged 1 commit intoscikit-learn:masterfrom
alexhenrie:prealloc

Conversation

@alexhenrie
Copy link
Copy Markdown
Contributor

By my benchmarks, this way takes 1% less time and 1% less memory. Plus, it makes error handling a lot easier.

@alexhenrie alexhenrie changed the title PERF Only call malloc once in liblinear to_sparse helpers (#16148) PERF Only call malloc twice in liblinear to_sparse helpers (#16148) Jun 24, 2019
@alexhenrie alexhenrie changed the title PERF Only call malloc twice in liblinear to_sparse helpers (#16148) PERF Only call malloc twice in liblinear to_sparse helpers Jun 25, 2019
@jnothman
Copy link
Copy Markdown
Member

jnothman commented Jun 26, 2019 via email

@alexhenrie
Copy link
Copy Markdown
Contributor Author

@rth Could you merge this please? Feel free to run your own benchmarks.

@rth
Copy link
Copy Markdown
Member

rth commented Jul 3, 2019

Thanks @alexhenrie , I'm just not too confident in my ability to review C code.

Maybe @jeremiedbb or @pierreglaser would be interested in doing a second review?

@jeremiedbb
Copy link
Copy Markdown
Member

We looked at it with pierre and it seems fine.
I agree with joel that you should add a comment in the code of free_problem to explain why you only need to free problem[0].

There's one thing not related to this PR still. When the malloc fails, the error is not handled anywhere after in liblinear.pyx (unlike for libswm which handles the error in libsvm.pyx). We should handle it when calling set_problem in liblinear also.

@rth
Copy link
Copy Markdown
Member

rth commented Jul 3, 2019

Thanks @jeremiedbb , feel free to merge then )

@alexhenrie
Copy link
Copy Markdown
Contributor Author

@jeremiedbb Thanks for reviewing this! In his comment above, @jnothman said that he just wanted to know what the reason was and he did not think a comment is necessary in the code. If you want a C comment explaining free(problem->x[0]) I'm happy to add one, just let me know.

@jeremiedbb jeremiedbb merged commit 0f7e470 into scikit-learn:master Jul 5, 2019
@jeremiedbb
Copy link
Copy Markdown
Member

it's fine. It's not like we modify this code very often :)

Thanks @alexhenrie !

@alexhenrie
Copy link
Copy Markdown
Contributor Author

Thank you!

@alexhenrie alexhenrie deleted the prealloc branch July 8, 2019 17:28
koenvandevelde pushed a commit to koenvandevelde/scikit-learn that referenced this pull request Jul 12, 2019
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.

5 participants