You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "jonahaapala (via GitHub)" <gi...@apache.org> on 2025/06/30 22:24:32 UTC
[PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
jonahaapala opened a new pull request, #3173:
URL: https://github.com/apache/thrift/pull/3173
I noticed that when partial deserialization was added a new method `readFieldBeginData()` was added to elide the TField object creation. However, only the **TBinaryProtocol** takes advantage of this. This PR updates **TCompactProtocol** to do the same.
Also, while using the **TProtocol** helper method `readMap()` that takes a **ReadMapEntryCallback** I found myself wishing I could passing a separate keyCallback and valueCallback so my calling code can use method references/lambdas.
Another minor tweak in this area was the default `mapCreator` for maps and sets. In later versions of Java they added the `HashMap.newHashMap()` factory method which will size the table to prevent resizing when given an initial capacity that won't be exceeded. I don't know of an equivalent for HashSet, though the HashSet constructor that takes in a Collection also performs this optimization. I have added them here for convenience. I have noticed in the past that the Java thrift compiler initially sizes maps to 2x their size likely for this reason, so this is like an analogue to that. Perhaps the compiler should also be doing this, but I suspect it's of minor consequence either way.
While trying to utilize the **TProtocolDecorator** I was sad that none of the `skip*()` methods were delegated to. I mostly wanted `skipBinary()`, but added them all for completeness. Again, looks like these were added for partial deserialization so I assume it was just missed. I added a few more overrides to it as well to really treat it as a delegating wrapper.
--
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: dev-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "jonahaapala (via GitHub)" <gi...@apache.org>.
jonahaapala commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3028481664
https://github.com/apache/thrift/pull/3169
<img width="808" alt="image" src="https://github.com/user-attachments/assets/5fae7562-ead5-41ae-b1c4-985f144772b1" />
vs this PR:
<img width="797" alt="image" src="https://github.com/user-attachments/assets/ffb877ec-45c5-4de9-8e1f-5b83daa5c0be" />
Looks like the same failing cross tests
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3028593621
> > most of the cross tests are already broken
>
> Is there any context you can share on this? Seems concerning, no?
the context is complicated. for a while (almost a year I think) at least one of the language build/tests are failing, which prevents cross tests to run (we only run cross tests after all language builds are succeeded). when we finally fixed those and start running cross tests again, it's already failing.
for java related cross tests in particular, I _think_ it's mostly that there are some issue with java client's ssl setup in cross tests (for example, all the failures with go server and java client are with ssl).
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "jonahaapala (via GitHub)" <gi...@apache.org>.
jonahaapala commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3028519842
> most of the cross tests are already broken
Is there any context you can share on this? Seems concerning, no?
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "jonahaapala (via GitHub)" <gi...@apache.org>.
jonahaapala commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3025044505
I will just switch to 2*map size which is done elsewhere in the thrift code base
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3032934090
cc @jimexist can you take a look?
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3028807363
> anything else you need from me before a final review?
someone more familiar with java code probably should review it instead.
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "jonahaapala (via GitHub)" <gi...@apache.org>.
jonahaapala commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3025833585
hm now it's showing cross test failures.. didn't show that before 👀
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "jonahaapala (via GitHub)" <gi...@apache.org>.
jonahaapala commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3032917086
@fishy is there just a queue of PR reviews that I am behind, or how can I attract a Java code reviewer?
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "jonahaapala (via GitHub)" <gi...@apache.org>.
jonahaapala commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3293236985
@fishy @jimexist any updates here?
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3024860080
> > Which version is that first added
>
> The HashMap.newHashMap factory was add in Java 19, but I assumed we couldn't use it here for backwards compatibility so I basically just copied what it does here.
I don't think that's in compliance with JDK's nor Apache's license
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "jonahaapala (via GitHub)" <gi...@apache.org>.
jonahaapala commented on code in PR #3173:
URL: https://github.com/apache/thrift/pull/3173#discussion_r2178725034
##########
lib/java/src/main/java/org/apache/thrift/protocol/TCompactProtocol.java:
##########
@@ -944,6 +923,43 @@ public int getMinSerializedSize(byte type) throws TTransportException {
// -----------------------------------------------------------------
// Additional methods to improve performance.
+ @Override
+ public int readFieldBeginData() throws TException {
+ byte type = readByte();
+
+ // if it's a stop, then we can return immediately, as the struct is over.
+ if (type == TType.STOP) {
+ return TFieldData.encode(type);
+ }
+
+ return TFieldData.encode(getTType((byte) (type & 0x0f)), readFieldId(type));
+ }
+
+ // Only makes sense to be called by readFieldBegin and readFieldBeginData
+ private short readFieldId(byte type) throws TException {
+ short fieldId;
+
+ // mask off the 4 MSB of the type header. it could contain a field id delta.
+ short modifier = (short) ((type & 0xf0) >> 4);
+ if (modifier == 0) {
+ // not a delta. look ahead for the zigzag varint field id.
+ fieldId = readI16();
+ } else {
+ // has a delta. add the delta to the last read field id.
+ fieldId = (short) (lastFieldId_ + modifier);
+ }
+
+ // if this happens to be a boolean field, the value is encoded in the type
+ if (isBoolType(type)) {
+ // save the boolean value in a special instance variable.
+ boolValue_ = (byte) (type & 0x0f) == Types.BOOLEAN_TRUE ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ // push the new field onto the field stack so we can keep the deltas going.
+ lastFieldId_ = fieldId;
+ return fieldId;
+ }
Review Comment:
Just a copy of the existing code minus the TField allocation. But this should be logically equivalent.
<img width="1432" alt="image" src="https://github.com/user-attachments/assets/7911d383-8019-44bc-8a27-627738378990" />
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy merged PR #3173:
URL: https://github.com/apache/thrift/pull/3173
--
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: dev-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "jonahaapala (via GitHub)" <gi...@apache.org>.
jonahaapala commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3024839161
> Which version is that first added
The HashMap.newHashMap factory was add in Java 19, but I assumed we couldn't use it here for backwards compatibility so I basically just copied what it does here.
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "jonahaapala (via GitHub)" <gi...@apache.org>.
jonahaapala commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3025886606
still trying to get the cross tests running locally, but I don't logically see what I broke :/
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "jonahaapala (via GitHub)" <gi...@apache.org>.
jonahaapala commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3024897901
I'll undo it if it's really a concern, but it feels like fairly intuitive 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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3024486154
>In later versions of Java they added...
Which version is that first added? I _could_ be wrong but I believe we need to maintain compatibility with JDK 8.
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "jonahaapala (via GitHub)" <gi...@apache.org>.
jonahaapala commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3024894969
> I don't think that's in compliance with JDK's nor Apache's license
I'm just dividing the size by the load factor. It's not really ground breaking stuff...
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "jonahaapala (via GitHub)" <gi...@apache.org>.
jonahaapala commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3059510288
@fishy sorry to be a pest, but this is my first PR to the Thrift project so I'm wondering if you could set some expectations on how long reviews usually take? I'm not trying to be pushy, I'm just wondering.
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3025930115
most of the cross tests are already broken, you just want to check against a previous run to see whether there are new broken cross tests.
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "jonahaapala (via GitHub)" <gi...@apache.org>.
jonahaapala commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3025576531
It seems like all the failures are CPP related. I'm not sure how to resolve them.
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add various/minor changes to some TProtocols for consistency and convenience [thrift]
Posted by "jonahaapala (via GitHub)" <gi...@apache.org>.
jonahaapala commented on PR #3173:
URL: https://github.com/apache/thrift/pull/3173#issuecomment-3028800172
anything else you need from me before a final review?
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org