Skip to content

feat : ABI upgrade from abi_stabby to stabby since abi_stable is no longer maintained#21030

Open
coderfender wants to merge 28 commits intoapache:mainfrom
coderfender:feat_migrate_ffi_to_stabby
Open

feat : ABI upgrade from abi_stabby to stabby since abi_stable is no longer maintained#21030
coderfender wants to merge 28 commits intoapache:mainfrom
coderfender:feat_migrate_ffi_to_stabby

Conversation

@coderfender
Copy link
Copy Markdown
Contributor

@coderfender coderfender commented Mar 18, 2026

Which issue does this PR close?

Rationale for this change

What changes are included in this PR?

  • Replace abi_stable types with stabby equivalents:
    • RVec -> stabby::vec::Vec
    • RString -> stabby::string::String
  • Add custom FFI_Option and FFI_Result types since we have raw pointers and self referential pointers which can't implement IStable trait needed for stabby
  • Rename macros: rresultsresult, rresult_return sresult_return
  • Fix library path detection for debug/release builds in the example loader
  • Update README

Are these changes tested?

Yes . With df python bindings on DF 52 release

Are there any user-facing changes?

@coderfender
Copy link
Copy Markdown
Contributor Author

coderfender commented Mar 18, 2026

Linking Tim's PR here #21025

@coderfender coderfender changed the title feat : ABI change from abi_stabby to stabby feat : ABI upgrade from abi_stabby to stabby since abi_stable is no longer maintained Mar 18, 2026
@github-actions github-actions Bot added the ffi Changes to the ffi crate label Mar 19, 2026
@coderfender
Copy link
Copy Markdown
Contributor Author

  1. Removed abi_stable package dependency

  2. Replaced all abi_stable calls with stabby equivalents

  3. Used Vec<K,V> since stabby doesnt have HashMap support
    TODO :

  4. Work on WrappedArray / native arrow types integration (Original impl through ABI just assumed safe implementation through sabi. However, stabby's answer is a little different)

  5. Refactor / remove async-ffi module ( IMHO, this can be done in a separate followup PR)

@timsaucer
Copy link
Copy Markdown
Member

One of the things I've been thinking about here is doing some scale testing of performance, which I haven't done on the FFI crate really. I was thinking we could do something along the lines of using https://github.com/datafusion-contrib/datafusion-tpch to generate table providers at different scale factors. Then it would seem we could have a series of tests:

  1. Pure rust with no FFI work.
  2. Pure rust but using two modules and passing table provider via FFI.
  3. Expose table provider to python and test with datafusion-python.

The thing I like about doing this is that we would be able to see the impacts of each of the layers between the code, ideally going from 2->3 having near zero impact.

For such a test I would think about setting up a stream, reading in and dumping the data as fast as possible.

Since this is orthogonal to the actual FFI work you're proposing I might try setting this up on a test repo.

@coderfender coderfender force-pushed the feat_migrate_ffi_to_stabby branch from 7dea35a to 9834a59 Compare March 20, 2026 12:57
Comment thread datafusion/ffi/src/udf/mod.rs Outdated
Comment thread datafusion/ffi/src/util.rs Outdated
@coderfender
Copy link
Copy Markdown
Contributor Author

Merged with main and see some referenced older package. Working on fixing it to use stabby

@coderfender
Copy link
Copy Markdown
Contributor Author

Updated cargo format , changed table_provider_module to use the direct function pointer call instead of accessor method pattern used in abi_stable

@coderfender coderfender force-pushed the feat_migrate_ffi_to_stabby branch from 70a5478 to d6194b8 Compare March 20, 2026 23:11
@coderfender coderfender marked this pull request as ready for review March 20, 2026 23:21
@coderfender
Copy link
Copy Markdown
Contributor Author

Testing python bindings now with the new ABI

@coderfender
Copy link
Copy Markdown
Contributor Author

The df python bindings rendered through new stabby implementations seem to be working on my local machine

Copy link
Copy Markdown
Member

@timsaucer timsaucer left a comment

Choose a reason for hiding this comment

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

Really nice work on this. I've put in a few questions. I think it's really great that the vast majority of the changes are pretty simple and have 1-1 replacement.

Comment thread datafusion-examples/examples/ffi/ffi_module_interface/src/lib.rs
Comment thread datafusion-examples/examples/ffi/ffi_module_loader/src/main.rs
Comment thread datafusion/ffi/src/proto/logical_extension_codec.rs Outdated
Comment thread datafusion/ffi/src/udf/mod.rs Outdated
Comment thread datafusion/ffi/src/insert_op.rs Outdated
Comment thread datafusion/ffi/src/plan_properties.rs Outdated
Comment thread datafusion/ffi/src/table_source.rs Outdated
Comment thread datafusion/ffi/src/util.rs Outdated
Comment thread datafusion/ffi/src/volatility.rs Outdated
@coderfender
Copy link
Copy Markdown
Contributor Author

thank you for the comments @timsaucer . I will work on the comments and push a commit shortly

@coderfender coderfender force-pushed the feat_migrate_ffi_to_stabby branch from d63326d to 48926f9 Compare March 25, 2026 04:39
@coderfender
Copy link
Copy Markdown
Contributor Author

Pushed a commit to address review comments . Please take a look whenever you get a chance

@coderfender
Copy link
Copy Markdown
Contributor Author

I'll rebase this branch blue that we have FFI for Physical optimizer rule change merged to main

@coderfender coderfender force-pushed the feat_migrate_ffi_to_stabby branch from 7f4ba21 to eb18d0c Compare March 27, 2026 00:13
@coderfender coderfender force-pushed the feat_migrate_ffi_to_stabby branch from eb18d0c to 08b4117 Compare March 27, 2026 03:04
@coderfender
Copy link
Copy Markdown
Contributor Author

@timsaucer , I updated PhysicalOptimizerRule to use stabby instead of abi_stable as well. Please take a look whenever you get a chance . Thank you

@timsaucer
Copy link
Copy Markdown
Member

After some thorough testing on leaning into the macros of the stabby crate, I have come to agree that your approach here is the best path forward. I think we need additional documentation in the FFI crate's readme to explain why we are limiting ourselves to basically using some of the stabby structs but not leaning into the macros it comes with. That way future developers do not ask the same questions, especially since stabby appears to do many of the things we would want.

@coderfender
Copy link
Copy Markdown
Contributor Author

Thank you for the update @timsaucer . Let me go ahead and update the docs to better reflect our approach here

Comment thread datafusion/ffi/src/util.rs Outdated
pub type FFIResult<T> = RResult<T, RString>;
/// back. These are converted back and forth using the `df_result`, `sresult`,
/// and `sresult_return` macros.
pub type FFIResult<T> = FFI_Result<T, SString>;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Having both a FFIResult<T> and a FFI_Result<T, SString> is confusing. Can we merge down to one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great point ! sure

Copy link
Copy Markdown
Contributor Author

@coderfender coderfender Apr 22, 2026

Choose a reason for hiding this comment

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

Given that there is only String based error usage across migration, we might not even need <T,E> and could consolidate this into just FFIResult<T>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, FFI_Result<T> to be consistent with the rest of the repo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Absolutely! I made changes to have one result used and exposed outside

Comment thread datafusion/ffi/README.md
about this approach see the [stabby] and [async-ffi] crates.

If you have a library in another language that you wish to interface to
DataFusion the recommendation is to create a Rust wrapper crate to interface
Copy link
Copy Markdown
Member

@timsaucer timsaucer Apr 22, 2026

Choose a reason for hiding this comment

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

For users who are interested in working on this code, they will probably ask themselves the same thing I asked. Why is it we are not using the core features of stabby? You and I have both come to the same conclusion that especially with the work on getting the record batch stream converted over to using stabby it turns into a much different project, especially when it comes to build times with the heavy macro use.

I think we just need some documentation as mentioned in a prior comment.

@coderfender coderfender force-pushed the feat_migrate_ffi_to_stabby branch from a4e5903 to 71f1fde Compare April 22, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ffi Changes to the ffi crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove generational-arena from project

2 participants