-
Notifications
You must be signed in to change notification settings - Fork 25
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
Improve performance by 2x and add a basic benchmark test #159
Merged
Conversation
This file contains 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
Previously the Tuple check was done after we'd done all the other 'is it a generic type' checks and that resulted in walking a long recursion depth of the Tuple interface list because Tuple didn't match any known generics. But since it is assignable to a non-generic interface, we can do the test a lot earlier, in fact even before we worry about generics, and this removes 12s on a profiler run or 14.44% of execution time to 0.29%
…ed LINQ eval Callined .ToArray on the IEnumerable will force it to evaluate in place, whereas if we don't do that, it will not evaluate the iterator until later on (or possibly never). But this means we can't dispose of the PyObject instances in the tupleValues collection, because we don't know when they'll be evaluated. Instead, leave it to the GC to deref them
…the List constantly
…into profile_app
…into profile_app
tonybaloney
commented
Aug 23, 2024
…into profile_app
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
tonybaloney
changed the title
Add an app for performance profiling
Improve performance and add a basic benchmark test
Aug 23, 2024
This reverts commit 165d7b0.
Closed
tonybaloney
changed the title
Improve performance and add a basic benchmark test
Improve performance by 2x and add a basic benchmark test
Aug 28, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request includes several changes aimed at improving the codebase by simplifying methods, optimizing performance, and enhancing readability. The most important changes include refactoring type conversion methods, modifying internal API functions, and optimizing dictionary and list handling.
Refactoring type conversion methods:
src/CSnakes.Runtime/PyObjectTypeConverter.BigInteger.cs
: Simplified theConvertToBigInteger
andConvertFromBigInteger
methods by removing unnecessary parameters and directly returning the parsedBigInteger
.src/CSnakes.Runtime/PyObjectTypeConverter.Dictionary.cs
: Refactored theConvertToDictionary
andConvertFromDictionary
methods to optimize key handling and reduce heap allocations.src/CSnakes.Runtime/PyObjectTypeConverter.List.cs
: Improved theConvertToList
andConvertToListFromSequence
methods by pre-allocating list sizes and simplifying the conversion process.src/CSnakes.Runtime/PyObjectTypeConverter.Tuple.cs
: Refactored theConvertFromTuple
andConvertToTuple
methods to streamline tuple handling and optimize nested tuple processing.Modifying internal API functions:
src/CSnakes.Runtime/CPython/Bool.cs
: Updated theIsPyBool
method to directly compare the handle withPy_True
andPy_False
for better performance.src/CSnakes.Runtime/CPython/Exceptions.cs
: Refactored thePyErr_Occurred
method to return a boolean and introduced a privatePyErr_Occurred_
method for internal use.src/CSnakes.Runtime/CPython/Long.cs
: Added a new methodPyLong_AsLong
to handle long integer conversions.src/CSnakes.Runtime/CPython/Tuple.cs
: Introduced new methodsPyTuple_GetItemWithNewRef
andPyTuple_GetItemWithNewRefRaw
to handle tuple item retrieval with new references. [1] [2]src/CSnakes.Runtime/CPython/Unicode.cs
: Added a new methodPyUnicode_AsUTF8Raw
for UTF-8 string conversion.Optimizing dictionary and list handling:
src/CSnakes.Runtime/PyObjectTypeConverter.Dictionary.cs
: Enhanced dictionary conversion by directly working with raw handles and optimizing key-value pair processing.src/CSnakes.Runtime/PyObjectTypeConverter.List.cs
: Improved list conversion by pre-allocating list sizes and simplifying item conversion.These changes collectively improve the efficiency and readability of the codebase, making it easier to maintain and extend in the future.