Skip to content

[FFI] Introduce small string/bytes #18185

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

Merged
merged 1 commit into from
Aug 4, 2025
Merged

Conversation

tqchen
Copy link
Member

@tqchen tqchen commented Aug 2, 2025

This PR introduces small string support to the FFI system. When the string length fit into the space in TVMFFIAny (aka len(str) <= 7). We directly store the string content into the TVMFFIAny content instead of creating a Object. This change will likely speedup small string access.

Some implications:

  • Always check for kTVMFFISmallStr code as well as kTVMFFIStr
  • Always check for kTVMFFISmallBytes when checking kTVMFFIBytes
  • Avoid using details::StringObj, instead, always use any.as()
  • Always set any.padding to 0 for other values (in compiler and runtime) to enable fast cmp

This PR introduces small string support to the FFI system.
When the string length fit into the space in TVMFFIAny (aka len(str) <= 7).
We directly store the string content into the TVMFFIAny content instead of creating a Object.
This change will likely speedup small string access.

Some implications:

- Always check for kTVMFFISmallStr code as well as kTVMFFIStr
- Always check for kTVMFFISmallBytes when checking kTVMFFIBytes
- Avoid using details::StringObj, instead, always use any.as<String>()
- Always set any.padding to 0 for other values (in compiler and runtime) to enable fast cmp
@Hzfengsy Hzfengsy merged commit fe36bb9 into apache:main Aug 4, 2025
13 checks passed
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.

2 participants