Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 11, 2025

Summary

This PR implements the C# equivalent of the C++ DIRECT_METHOD_CALL macro in the ILinksExtensions class to enable performance optimizations similar to those available in the C++ version.

🎯 Fixes Issue

Fixes #125 - Use DIRECT_METHOD_CALL in ILinks extensions

🔧 Implementation Details

Added DirectMethodCall Helper Method

  • Created a private DirectMethodCall<TLinkAddress, TConstants, TResult> helper method
  • Marked with [MethodImpl(MethodImplOptions.AggressiveInlining)] for JIT optimization
  • Allows the JIT compiler to potentially devirtualize method calls when concrete types are known

Updated Method Calls

The following methods now use DirectMethodCall for performance optimization:

  • Create methods: Both overloads now use DirectMethodCall for links.Create() calls
  • Update method: Uses DirectMethodCall for links.Update() calls
  • Delete method: Uses DirectMethodCall for links.Delete() calls
  • Exists method: Uses DirectMethodCall for links.Count() calls
  • Each method: Uses DirectMethodCall for links.Each() calls
  • GetLink method: Uses DirectMethodCall for internal links.Each() calls

🚀 Performance Benefits

In C++, DIRECT_METHOD_CALL macro conditionally calls methods directly on concrete types vs through virtual dispatch:

#define DIRECT_METHOD_CALL(TClass, Object, MethodName, ...) \
  (std::is_abstract<TClass>::value ? Object.MethodName(__VA_ARGS__) : Object.TClass::MethodName(__VA_ARGS__))

In C#, the DirectMethodCall helper enables similar optimizations by:

  • Providing a consistent pattern for method invocation
  • Allowing the JIT compiler to optimize calls when concrete types are known at compile time
  • Maintaining the same semantic behavior as direct calls

✅ Testing

  • ✅ All existing tests pass
  • ✅ Build succeeds without errors
  • ✅ No breaking changes to public API

📝 Code Quality

  • Maintains existing code style and conventions
  • Preserves all XML documentation
  • Uses consistent naming patterns
  • Follows the established architectural patterns

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #125
@konard konard self-assigned this Sep 11, 2025
konard and others added 2 commits September 11, 2025 11:47
Implements C# equivalent of the C++ DIRECT_METHOD_CALL macro by introducing
a DirectMethodCall helper method that enables JIT compiler optimizations
for method calls when the concrete type is known at compile time.

Changes:
- Added DirectMethodCall helper method with AggressiveInlining attribute
- Updated Create, Update, Delete methods to use DirectMethodCall
- Updated Count calls in Exists method to use DirectMethodCall
- Updated Each method calls to use DirectMethodCall
- Updated GetLink method to use DirectMethodCall for Each call

This optimization allows the JIT compiler to potentially devirtualize
method calls when the concrete implementation type is known, similar
to how the C++ DIRECT_METHOD_CALL macro works.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Use in ILInks extensions Use DIRECT_METHOD_CALL equivalent in C# ILinksExtensions Sep 11, 2025
@konard konard marked this pull request as ready for review September 11, 2025 08:53
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.

Use DIRECT_METHOD_CALL in ILInks extensions

2 participants