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

Unneded string interpolation of characteristics is very resource hungry #708

Open
bobatsar opened this issue Mar 20, 2023 · 5 comments
Open

Comments

@bobatsar
Copy link

The logger output in reactive_ble_mobile_platform.dart, is evaluated for each received message. Especially the interpolation of the characteristic is quite resource hungry. We are receiving a lot of characteristics data and this string interpolation takes up about 10-15% of CPU usage for our data handling.

_logger?.log(
'Received $CharacteristicValue(characteristic: ${update.characteristic}, result: ${update.runtimeType})',
);

Unfortunately the logger is always initialized via the following code and I don't see any way to disable it.

Future<void> initialize() async {
if (_initialization == null) {
_debugLogger = DebugLogger(
'REACTIVE_BLE',
print,
);

Can this be refactored, that the logger does not have to be initialized and can be set to null if not used? AFAIK then the interpolation would not be executed, resulting in less CPU usage.

@Taym95
Copy link
Collaborator

Taym95 commented Jun 4, 2024

if you set logLevel to LogLevel.none you will disable logs

@Taym95 Taym95 closed this as completed Jun 4, 2024
@bobatsar
Copy link
Author

bobatsar commented Jun 5, 2024

Hi @Taym95,

the issue is, that even when setting the logLevel to LogLevel.none the string interpolation still happens.
There is nothing is logged in the end but the calculations are already done. When the logger is set to null this does not happen.

Can you please reopen this ticket and also think about merging my PR #861?

@BenelliFurtado
Copy link

I noticed the same issue a few lines below. Our app is permanently scanning for Bluetooth devices and this is actually a big part of the used CPU!

_logger?.log(
'Received $ScanResult(result: ${scanResult.result})',
);

@Taym95 Taym95 reopened this Jun 5, 2024
@BenelliFurtado
Copy link

Here is a screenshot from Flutter devtools. Notice the toString method in blue:

flutter_reactive_toString

@bobatsar
Copy link
Author

bobatsar commented Jun 5, 2024

Hi @BenelliFurtado, yes that's the same issue. I am currently working on it and it seems my PR will be merged soon.

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

3 participants