[BY DESIGN] Slow response to external ISR when using AttachInterrupt

LibMaple (The core that Roger's repo uses)
stevestrong
Posts: 1740
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Slow response to external ISR when using AttachInterrupt

Post by stevestrong » Tue Aug 29, 2017 4:19 pm

victor_pv wrote:
Tue Aug 29, 2017 3:54 pm
So I can register the same function to be called, but for line 1 the arg parameter could be a 1, and for line 2 arg could be a 2, so when my function is called I know which line is causing the call.
Of course I could write 2 different ISRs, but perhaps the function has to do exactly the same process, so writing twice the same function is a waste.
I see here a kind of overkill: once you have different functions for different pins, why do you need extra different arguments?
Of course, it is possible to use same function for different pins, but it makes not much sense. Even though, you could manage that use case by defining Func1(), Func2(), Func3() each of them calling Func0(param) with different parameters, thus having minimal overhead, but speedy execution.

victor_pv
Posts: 1681
Joined: Mon Apr 27, 2015 12:12 pm

Re: Slow response to external ISR when using AttachInterrupt

Post by victor_pv » Tue Aug 29, 2017 7:42 pm

Yeah I guess it could be done that way too. I just think that may have been the intention for leaflabs when they added that argument, or perhaps to pass a class pointer since the argument is a pointer, so each ping could have a pointer to a class, and a pointer to a function within that class.

But if you remove it, just make sure we don't see that being used in any library.

User avatar
RogerClark
Posts: 7145
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Slow response to external ISR when using AttachInterrupt

Post by RogerClark » Tue Aug 29, 2017 10:30 pm

I checked the official API and the handler does not receive an argument.

I doubt anyone has used this feature, so I think it would be fairly safe to remove it.


But I still don't see the problem with removing the null pointer check before calling the handler, as it is far more efficient to put that check in the code that sets up the handler than to check it every time there is an interrupt

victor_pv
Posts: 1681
Joined: Mon Apr 27, 2015 12:12 pm

Re: Slow response to external ISR when using AttachInterrupt

Post by victor_pv » Thu Aug 31, 2017 2:46 pm

Perhaps run a test with both options and compare code size, ram used, and latency?
I think checking for Null should not cost many cycles, and calling any function, even a dummy one, may cost more, but who knows what the compiler will do when optimizing.

User avatar
RogerClark
Posts: 7145
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Slow response to external ISR when using AttachInterrupt

Post by RogerClark » Fri Sep 01, 2017 12:24 am

I ran Pitos test and removed the check for the null hander as as expected its a bit faster, by around 75nS I think.

I've not tried removing the argument passing

I've also not ran the dhrystone test with this change to see if it would impact overall performance, but I can't see how it could do that, unless there is some other bug in the code where an interrupt is constantly getting triggered on a null handler

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: Slow response to external ISR when using AttachInterrupt

Post by danieleff » Fri Sep 01, 2017 9:13 am

RogerClark wrote:
Tue Aug 29, 2017 10:30 pm
I checked the official API and the handler does not receive an argument.

I doubt anyone has used this feature, so I think it would be fairly safe to remove it.
FYI: here is the official Arduino PR for this feature: https://github.com/arduino/Arduino/pull/4519

stevestrong
Posts: 1740
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Slow response to external ISR when using AttachInterrupt

Post by stevestrong » Fri Sep 01, 2017 9:24 am

I am still not convinced that this is really useful.
The context dependent parameter passing, when needed, can be replaced by implementing the CB function in a different way.

User avatar
RogerClark
Posts: 7145
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Slow response to external ISR when using AttachInterrupt

Post by RogerClark » Fri Sep 01, 2017 10:12 am

OK

Lets leave this.

The Arduino API is designed for ease of use at the expense of speed and memory etc.

So what we now have works OK, and if someone needs a faster implementation they can play with the vector table directly etc

Post Reply