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

Performance #18

Open
iadonkey opened this issue Jan 7, 2024 · 2 comments
Open

Performance #18

iadonkey opened this issue Jan 7, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@iadonkey
Copy link

iadonkey commented Jan 7, 2024

Hi!

this is not an issue, but only a discussion…
At Zeugwerk we have a pretty similar logger and are currently implementing a fluent API for it (atm our API is not fluent) - in general our logging mechanism has some major differences to TcLog, because we don’t use a singleton pattern, but allow several loggers to be used in a single PLC and require logging into multiple log targets to be thread-safe.

I played around a bit on how to implement the fluent API for it and found that having the log level as the first call can improve the performance a lot.
Our API, coming with Zeugwerk Framework 1.6, will look like this

_logger.AtInfo().LogMessage('I am a log message);
_logger.AtTrace().WithCondition(boolean1).Append('Number ').AppendInt(5).Append(' is alive').LogMessage('');
_logger.AtWarning().WithRisingTrigger(boolean1).LogMessage('boolean1 just got true');

having the log level as the „initiating“ call to the fluent API, has the advantage that a log message can be immediately discarded if the minimum log level as not satisfied, also if any „with“ condition is not met the message can be discarded. A discarded message doesn’t need any string operations, so besides the calls to the methods and an „if discarded then return“ the messages are for free.

What do you think of this?

@bengeisler
Copy link
Owner

Good morning! This sounds reasonable. It also gets rid of empty strings in the error etc. which bothered me stylistically for some time:

_logger.AppendString('...').AppendAny(myInt).Error('');

I'm a bit short on time right now but I'll look into it once I find some free hours.

Did you use a profiler to track this performance issue down? Which one did you use?

@bengeisler bengeisler added the enhancement New feature or request label Jan 8, 2024
@iadonkey
Copy link
Author

iadonkey commented Jan 8, 2024

I just did some small tests with https://infosys.beckhoff.com/english.php?content=../content/1033/tcplclib_tc2_system/30963979.html&id= in our new implementation for the API. In general for logging just a string with any concatenation the fluent API has an additional call compared to a simple logger.Trace(…)

but I‘ll do some profiling later on with https://github.com/stefanbesler/twingrind , in our implementation we‘ll have both APIs anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants