Encoding: native handle where it is born, value where it is cheapest#485
Merged
Conversation
Minimize JNI crossings for every encoding flow (consumes zenoh-flat-jni PR #5): - Predefined constants stay VALUE-ONLY: a send carries just their id inside the send call itself — no native handle ever exists for them, no extra crossing. - Custom (schema-carrying) encodings create their native handle at construction — the one natural crossing — and every send after passes a bare jlong (borrowed and cloned natively, reusable forever). - Received encodings (sample/query/reply) arrive send-ready: the delivery decomposition now includes the owned handle, so the save-and-republish scenario never rebuilds the native value from its schema string. Handle release is GC-managed (EncodingCleaner in the shared tier); Encoding stays a plain non-closeable value with unchanged (id, schema) equality/rendering. Send call sites drive the generated encoding selector block through the internal Encoding?.jniSel/jniId/jniSchema/jniHandle helpers — one flat call, zero extra crossings in every case. New EncodingHandleTest covers the ownership model end-to-end; 110 jvm tests green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
zenoh-flat-jni's Encoding, Session, Publisher, Subscriber, Queryable, Querier, Scout, LivelinessToken and Query handles are now gc_managed (milyin/prebindgen#82): a shared Cleaner frees an unreachable handle whose owner never released it, with explicit close/undeclare settling the release ticket first. Delete the 8 deprecated-for-removal finalize() nets (JEP 421) — the JNI handle is its own backstop now — and drop Encoding's EncodingCleaner registration (superseded by the gc_managed class; the hand-written helper is deleted in zenoh-flat-jni). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
|
Second commit ( |
The encoding selector wire shape and gc_managed lifecycles this branch consumes landed in ZettaScaleLabs/zenoh-flat-jni#5 (e802317); the old pin predates it, so CI compiled against the previous (present, id, schema) encoding signatures. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or 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
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.
What
Implements the encoding crossing-minimization model on top of ZettaScaleLabs/zenoh-flat-jni#5. The save-and-republish scenario (receive a sample with a custom encoding, keep the
Encoding, pass it tosession.put) no longer rebuilds the native encoding from its schema string on any send.The ownership model:
(id, schema=null): a send carries just the id inside the send call itself — no native handle ever exists for them, no extra crossing.Encoding.from("…;schema"),withSchema) — the one natural crossing — and every send after passes a barejlong(the native side borrows and clones, so the handle is reusable forever).Encodingstays a plain non-closeable value —(id, schema)equality/rendering viaEncodingCodecunchanged; handle release is GC-managed (EncodingCleaner, shared bindings tier).How
Encodinggains aninternal val handle: JniEncoding?seeded at construction (custom) or delivery (received);EncodingCleaner.registerininit.Sessionput/get/declarePublisher,Publisher.performPut,Query.reply/replyErr,Querier.get) drive the generated encoding selector block through internalEncoding?.jniSel/jniId/jniSchema/jniHandleextension helpers — one flat call, zero extra crossings for the absent/preset/handle cases alike.FlatCallbacks+Sample.fromParts/Query.fromPartstake the new handle leaf.Tests
New
EncodingHandleTest(4 tests): presets never grow a handle (even after being sent), custom encodings own one from construction, a received encoding is send-ready and re-sends by the same untouched handle, preset round-trip. Full suite: 110 jvmTest, 0 failures.Sequencing
Requires ZettaScaleLabs/zenoh-flat-jni#5 (the local composite build already provides it; Maven consumers need the flat-jni release).
🤖 Generated with Claude Code