Skip to content
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

Small ring chunk source cleanup #5502

Merged
merged 4 commits into from
May 17, 2024

Conversation

devinrsmith
Copy link
Member

@devinrsmith devinrsmith commented May 16, 2024

This was originally explored as a fix for #5498; ultimately, it was an upstream data issue that was solved in #5503. Along the way though, it was noted that ring chunk sources were 1) using reflection in places they didn't need to, and 2) using specifically typed arrays for generic types as opposed to other object chunks which use Object[] at the top layer. In the latest iteration of this, the construction reflection was removed (there is a new getLength check); but I'm apt to keep the more specifically typed arrays unless we know they are causing other issues. At a minimum, the specifically typed arrays helped us notice and fix #5503.

This reduces the type checking for ring table chunk sources; essentially, matching the expectations that we might need to copy around empty `Object[0]` as a substitute for the more specifically typed empty array. While I'm not the biggest fan of persisting this (ab)use of the type system, it is out of scope to actually try and plumb correct typing throughout the stack at this time.

Fixes deephaven#5498
@devinrsmith devinrsmith added this to the 3. May 2024 milestone May 16, 2024
@devinrsmith devinrsmith requested a review from rcaudy May 16, 2024 22:17
@devinrsmith devinrsmith self-assigned this May 16, 2024
@devinrsmith
Copy link
Member Author

I guess this use of the type system, while (ab)using Object[0], may be more generously described as being able to cast to super types for "free" (for read only use cases), and more specific types for "free" (for writing use cases), although those have there own risks as well.

@@ -73,7 +73,13 @@ public AbstractRingChunkSource(@NotNull Class<T> type, int capacity) {
}
this.capacity = capacity;
// noinspection unchecked
ring = (ARRAY) Array.newInstance(type, capacity);
ring = type.isArray()
Copy link
Member

Choose a reason for hiding this comment

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

I think the wider issue here is that this code is using reflection to determine the array type instead of using inheritance (and using Object[] to hold non-primitive values).

Copy link
Member

Choose a reason for hiding this comment

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

Are you certain you shouldn't be using Object[] in more cases?

Copy link
Member

Choose a reason for hiding this comment

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

Never mind, we figured out that we were dealing with weird upstream data.

@devinrsmith devinrsmith changed the title Fix ring table for nested arrays Small ring chunk source cleanup May 16, 2024
@devinrsmith devinrsmith requested a review from rcaudy May 16, 2024 23:30
@devinrsmith devinrsmith enabled auto-merge (squash) May 16, 2024 23:33
@devinrsmith devinrsmith merged commit 0b07eb9 into deephaven:main May 17, 2024
14 checks passed
@devinrsmith devinrsmith deleted the fix-ring-table-nested-arrays branch May 17, 2024 00:06
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants