CurtHagenlocher opened a new pull request, #4917:
URL: https://github.com/apache/arrow-adbc/pull/4917

   ## What's changed
   
   A driver published with NativeAOT gets its own GC heap, and the runtime only 
collects that heap in response to allocations. Nothing collects it on a timer, 
and the low-memory notification doesn't collect an idle heap either. So once a 
caller releases its databases, the memory the driver last used stays committed 
for the rest of the process's life.
   
   `CAdbcDriverExporter` now counts the databases it has open. A collection is 
scheduled when the last database is released, or when the driver is released 
while no databases are open. It runs on a thread-pool thread after 
`IdleCollectionDelay`, and only if no database was opened in the meantime. The 
collection is `Collect` + `WaitForPendingFinalizers` + an aggressive, 
compacting gen2 collection.
   
   - `IdleCollectionDelay` is a new public static `TimeSpan?`, and `null` turns 
the feature off.
   - It defaults to one second when running under NativeAOT 
(`!RuntimeFeature.IsDynamicCodeSupported`). It defaults to `null` under JIT, 
where the driver shares its heap with the host, and on the `netstandard2.0` 
build.
   - Waiting for finalizers is needed for now because exported record batches 
are freed by their finalizers rather than when the consumer releases them 
(apache/arrow-dotnet#464).
   - A plain `GC.Collect()` empties the heap but leaves the memory committed. 
`GCCollectionMode.Aggressive` decommits it.
   
   ### Measurements
   
   A NativeAOT driver built on the exporter was loaded by a C host, which ran a 
workload and then released everything. The host never asks for a collection. 
Numbers are process private bytes; the baseline is about 3 MB.
   
   | Workload | After release | 10 s later, before | 10 s later, after |
   |---|---|---|---|
   | 2 × 6 batches × 4M rows | 419 MB | 419 MB | 5.9 MB |
   | 3 × 50 batches × 64K rows | 24.5 MB | 24.5 MB | 4.4 MB |
   
   The forced collection took 2–32 ms in these runs.
   
   ### Tests
   
   `IdleCollectorTests` covers:
   - collecting after the last database is released;
   - collecting only once when the driver is released after the databases;
   - skipping when a database is reopened during the delay;
   - collecting again after a later idle period;
   - disabling with a `null` delay, and rejecting a negative delay;
   - the JIT default.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to