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

Intern string #1254

Merged
merged 2 commits into from Nov 6, 2020
Merged

Intern string #1254

merged 2 commits into from Nov 6, 2020

Conversation

amos402
Copy link
Member

@amos402 amos402 commented Oct 9, 2020

What does this implement/fix? Explain your changes.

Use the intern strings map to const strings instead of creating temporary strings everytimes.

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • If an enhancement PR, please create docs and at best an example
  • Add yourself to AUTHORS
  • Updated the CHANGELOG

src/runtime/intern.cs Outdated Show resolved Hide resolved
Comment on lines +1 to +4
<#@ template debug="true" hostSpecific="true" #>
<#@ output extension=".cs" #>
<#
string[] internNames = new string[]
Copy link
Member

Choose a reason for hiding this comment

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

Why use a template generator, when you can simply get internNames from reflection? It looks like unnecessary complication.

Copy link
Member Author

Choose a reason for hiding this comment

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

Two reasons make this scenario happened.

  1. You need to make sure the string is a c# intern string too to make code like this work without extra checking
const string s = "1";
switch (
    case "1":
        // both "1" point to the same string
       break;
  1. If you need (1), you have to make the internNames set on compile.
    Of course, if you don't (1), internNames can just set by using reflection from reading PyIdentities.

src/runtime/intern.cs Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Oct 22, 2020

Codecov Report

Merging #1254 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1254   +/-   ##
=======================================
  Coverage   86.25%   86.25%           
=======================================
  Files           1        1           
  Lines         291      291           
=======================================
  Hits          251      251           
  Misses         40       40           
Flag Coverage Δ
setup_linux 64.94% <ø> (ø)
setup_windows 72.50% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 84e2735...f2a6621. Read the comment docs.

src/runtime/intern.cs Show resolved Hide resolved
@lostmsu
Copy link
Member

lostmsu commented Nov 5, 2020

@amos402 did you have a chance to compare benchmarks on your branch with InteropString.GetManagedString replaced by Runtime.GetManagedString?

@amos402
Copy link
Member Author

amos402 commented Nov 6, 2020

https://gist.github.com/amos402/8decd54dee57fe654e098bc0b15c061a

CPU: Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz
Python Version: 3.8.6

function origin intern-string without Intern.GetManagedString
get_doc 0.31777 (100.00%%) 0.18106 (56.98%%) 0.32203 (101.34%%)
get_attr_doc 0.3397 (100.00%%) 0.20156 (59.33%%) 0.34397 (101.26%%)
get_attr_doc_concat 0.34546 (100.00%%) 0.42619 (123.37%%) 0.34862 (100.91%%)

@lostmsu lostmsu merged commit d0c588b into pythonnet:master Nov 6, 2020
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

Successfully merging this pull request may close these issues.

None yet

3 participants