Intern string by amos402 · Pull Request #1254 · pythonnet/pythonnet
Conversation
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.
Comment on lines +1 to +4
| <#@ template debug="true" hostSpecific="true" #> | ||
| <#@ output extension=".cs" #> | ||
| <# | ||
| string[] internNames = new string[] |
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.
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.
- 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;
- If you need (1), you have to make the
internNamesset on compile.
Of course, if you don't (1), internNames can just set by using reflection from readingPyIdentities.
Codecov Report
Merging #1254 into master will not change coverage.
The diff coverage isn/a.
@@ 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.
@amos402 did you have a chance to compare benchmarks on your branch with InteropString.GetManagedString replaced by Runtime.GetManagedString?
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%%) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters