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

[AOT] Refactor Logger function to improve performance and mark managedCommon as AOT compatible #36327

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

moooyo
Copy link
Contributor

@moooyo moooyo commented Dec 13, 2024

Summary of the Pull Request

  • clean up some AOT build issue
  • Refactor Log function. Use System.AppContext to get the application path.
  • Log CallerMemberName, File, LineNumber in logger and remove GetCallerInfo.

To drop all reflection usage, we can get about 18% performance improvement by this PR change. Here's a simple test which call Logger.LogError 100k times. (Left: before this change, Right with this change)
image

By this change, we can remove the wired useage of reflection which try to get some infromation from stack frame. It's hard to understand and maintain.

About the log format. I've compared the advancedPaste module's log. Most of them are equal, but some of them are not the same.
Such as:
image
image
The original code will retrieve the caller info from the stack frame. The caller name will be so strange in some case. After this change merged, we will get a more clear information.

PR Checklist

  • Closes: #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

@moooyo moooyo added the Needs-Review This Pull Request awaits the review of a maintainer. label Dec 13, 2024
@moooyo
Copy link
Contributor Author

moooyo commented Dec 13, 2024

When we publish application with AOT enable. Some reflection usage will be forbidden. So, we need to make this change.

@crutkas crutkas added In for .88 Don't merge - Hold for release Hold off on merging this PR, even if it's approved. labels Dec 13, 2024
Copy link

@yeelam-gordon yeelam-gordon left a comment

Choose a reason for hiding this comment

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

I believe we need advice + know the knowledge on how to analysis PowerToys logging :-D

src/common/ManagedCommon/Logger.cs Outdated Show resolved Hide resolved
}

private static MethodBase GetCallerMethod(StackTrace stackTrace)
private static string GetCallerInfo(string memberName, string sourceFilePath, int sourceLineNumber)

Choose a reason for hiding this comment

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

For sourceLineNumber.
Given originally they don't have, we need to ask for PMs, that any parser of the log it will break this.
If Yes, we should still keep the original "TypeName::MethodName" format first.

Last but not least, do we know how to view PowerToys log? If we can parrse the log and show a summary of before after, it will give confidence of this changes.

{
Log(string.Empty, TraceFlag);
Log(string.Empty, TraceFlag, memberName, sourceFilePath, sourceLineNumber);
}

[MethodImpl(MethodImplOptions.NoInlining)]

Choose a reason for hiding this comment

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

May be we don't need this one anymore.

@@ -53,18 +52,37 @@ public static void InitializeLogger(string applicationLogPath, bool isLocalLow =
Trace.AutoFlush = true;
}

public static string GetVersion()

Choose a reason for hiding this comment

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

Can we just ask the caller to pass in its own class type?
From Github copilot, the following code should be AOT compatible:
var versionInfo = FileVersionInfo.GetVersionInfo(typeof(Program).Assembly.Location);
Console.WriteLine($"Version: {versionInfo.FileVersion}

@jaimecbernardo jaimecbernardo removed the Don't merge - Hold for release Hold off on merging this PR, even if it's approved. label Dec 18, 2024
@moooyo moooyo marked this pull request as ready for review December 19, 2024 01:53
@moooyo
Copy link
Contributor Author

moooyo commented Dec 20, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@moooyo moooyo changed the title [AOT] Refactor Logger function and mark managedCommon as AOT compatible [AOT] Refactor Logger function to improve performance and mark managedCommon as AOT compatible Dec 24, 2024
@moooyo moooyo requested review from crutkas and snickler December 24, 2024 04:51
@moooyo
Copy link
Contributor Author

moooyo commented Dec 25, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In for .88 Needs-Review This Pull Request awaits the review of a maintainer.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

4 participants