You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "voonhous (via GitHub)" <gi...@apache.org> on 2026/06/13 10:32:08 UTC

Re: [PR] perf(common): Avoid per-record HoodieSchema rebuilds on Avro read/merge paths [hudi]

voonhous commented on code in PR #18967:
URL: https://github.com/apache/hudi/pull/18967#discussion_r3407809233


##########
hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchema.java:
##########
@@ -1153,7 +1155,11 @@ public List<HoodieSchemaField> getFields() {
       throw new IllegalStateException("Cannot get fields from schema type: " + type);
     }
     if (fields == null) {
-      fields = Collections.unmodifiableList(avroSchema.getFields().stream().map(HoodieSchemaField::new).collect(Collectors.toList()));
+      synchronized (this) {

Review Comment:
   Okay, dropped the `synchronized` double-checked locking in both `getFields()` and `getFieldMap()` for a benign racy single-check. Since the cached value is an immutable, deterministic view of the schema fields, concurrent first-callers may each build it once but converge on equal results. I kept the `volatile` on `fields`/`fieldMap` so the unmodifiable collections (which wrap a non-final-field ArrayList/HashMap) are still published safely on weak memory models - that avoids a reader ever seeing a partially-constructed collection.



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org