Skip to content

Reduce Callback.h using C++11 #10885

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

Merged
merged 1 commit into from
Jul 9, 2019
Merged

Conversation

kjbracey
Copy link
Contributor

Description

The bulk of Callback.h was auto-generated as 6 specialisations, handling zero to five arguments.

This can now be handled without specialisation using C++11 variadic templates, reducing the file from 4,900 lines to 900 lines.

This should reduce compilation time, and offset potential increases from use of <type_traits> or a local mbed_cxxsupport.h equivalent.

Several other improvents to Callback are possible and/or desirable with C++11, such as the ability to store lambdas, but this commit is purely the variadic simplification.

Pull request type

[ ] Fix
[X] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@pan-, @bulislaw, @geky

The bulk of Callback.h was auto-generated as 6 specialisations, handling
zero to five arguments.

This can now be handled without specialisation using C++11 variadic
templates, reducing the file from 4,900 lines to 900 lines.

This should reduce compilation time, and offset potential increases from
use of `<type_traits>` or a local `mbed_cxxsupport.h` equivalent.

Several other improvents to `Callback` are possible and/or desirable
with C++11, such as the ability to store lambdas, but this commit is
purely the variadic simplification.
@kjbracey
Copy link
Contributor Author

The header file is actually somewhat understandable after this - it is complex, but the previous version further obfuscated it by just repeating everything 6 times, meaning it was rather hard to visualise the structure.

C++11 could possibly simplify it further using type traits to cut out a bunch of the const/volatile overloading repetition.

@kjbracey
Copy link
Contributor Author

Could get it down to 500 lines if all the deprecated stuff was dropped...

Copy link
Member

@pan- pan- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look goods to me.
I've been working on a new implementation yesterday, that reduces the code size and simplify most of the (unnecessary) overloads and add other goodies. I will submit it once this first simplification goes in.

@ciarmcom ciarmcom requested review from bulislaw, geky, pan- and a team June 24, 2019 11:00
@ciarmcom
Copy link
Member

@kjbracey-arm, thank you for your changes.
@bulislaw @geky @pan- @ARMmbed/mbed-os-core @ARMmbed/mbed-os-maintainers please review.

Copy link
Contributor

@evedon evedon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great, thanks Kevin!
I was discussing with the team this optimisation just a few days ago as this file was really huge! Did not know that you had plan to work on it :)

@kjbracey
Copy link
Contributor Author

I've been working on a new implementation yesterday, that reduces the code size and simplify most of the (unnecessary) overloads and add other goodies. I will submit it once this first simplification goes in.

Cool. I'll hold off on my temptation to fiddle further then, and wait to review yours.

@pan-
Copy link
Member

pan- commented Jun 24, 2019

@evedon events/Event.h would also benefit from such simplification.

@kjbracey
Copy link
Contributor Author

It would make sense to do the same thing to Event.h at the same time. I can do that now, if no-one else has already done it.

@evedon
Copy link
Contributor

evedon commented Jun 24, 2019

It would make sense to do the same thing to Event.h at the same time. I can do that now, if no-one else has already done it.

We have not worked on it so feel free.

@kjbracey
Copy link
Contributor Author

Hmm, Event.h and EventQueue.h are much more complex, as they don't just have to forward variadic arguments, they have to store them (in the EventQueue::context<x><y> structure). Nowhere near as straightforward - solutions involve a bunch of extra standard library machinery like std::tuple, which we don't have for ARM C 5.

@evedon
Copy link
Contributor

evedon commented Jun 24, 2019

In that case, it is not worth doing it as part of this PR.

Copy link
Contributor

@geky geky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see this come in 👍

@kjbracey
Copy link
Contributor Author

Glad to see this come in 👍

No doubt this was what you were yearning to write in the first place. The hard part was generating the C++98 version!

Hmm, Event.h and EventQueue.h are much more complex,

Actually, they're not so bad. I think I can remove 95% of them - it's just the innermost struct context that will remain specialized. I'll make a separate PR for them.

@artokin
Copy link
Contributor

artokin commented Jul 8, 2019

@kjbracey-arm , what is status of this PR?

@kjbracey
Copy link
Contributor Author

kjbracey commented Jul 8, 2019

I think it's ready. Got a pile of design changes to follow, but this one's fine.

@artokin
Copy link
Contributor

artokin commented Jul 8, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Jul 8, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 1
Build artifacts

@artokin artokin removed the needs: CI label Jul 9, 2019
@artokin artokin merged commit 28eb39c into ARMmbed:master Jul 9, 2019
@kjbracey kjbracey deleted the callback_variadic branch July 16, 2019 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants