[ 
https://issues.apache.org/jira/browse/FLINK-39819?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gyula Fora closed FLINK-39819.
------------------------------
      Assignee: Dennis-Mircea Ciupitu
    Resolution: Fixed

merged to main 95fc69a4cc467d98a0475afaed7da9816a45378e

> Avoid redundant JSON String round-trips in SpecUtils.clone and 
> DiffResult.toString 
> -----------------------------------------------------------------------------------
>
>                 Key: FLINK-39819
>                 URL: https://issues.apache.org/jira/browse/FLINK-39819
>             Project: Flink
>          Issue Type: Improvement
>          Components: Kubernetes Operator
>    Affects Versions: kubernetes-operator-1.15.0
>            Reporter: Dennis-Mircea Ciupitu
>            Assignee: Dennis-Mircea Ciupitu
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: kubernetes-operator-1.16.0
>
>
> h1. Summary
> The operator deep-copies CRD objects and renders spec diffs by routing data 
> through a redundant JSON String. Both code paths serialize an in-memory 
> object to a String and then immediately parse that String back into an object 
> or a tree. The intermediate String is pure overhead and can be removed by 
> converting directly between the object and the in-memory representation.
> h1. Motivation
> Two utility paths build an intermediate JSON String that nothing else ever 
> consumes.
> h2. SpecUtils.clone (hot path)
> {{SpecUtils.clone}} is used by {{ReconciliationUtils.clone}} to deep-copy 
> Flink resources and their nested specs. It runs on every reconcile cycle, for 
> every managed resource. Each controller clones the full custom resource at 
> the start of reconciliation ({{FlinkDeploymentController}}, 
> {{FlinkSessionJobController}}), and additional clones happen for specs and 
> pod templates. The current implementation serializes the object to a String 
> and then parses that String back, which allocates and re-tokenizes the entire 
> object graph on a path that executes constantly.
> h2. DiffResult.toString (cold path)
> {{DiffResult.toString}} builds the human-readable message for the 
> {{SpecChanged}} Kubernetes event. It converts the before and after values to 
> JSON trees by going through an intermediate String. This path is low 
> frequency because it only runs when a user changes a spec, but it carries the 
> same redundant round-trip and the same pattern worth cleaning up for 
> consistency.
> h1. Expected Impact
> Removing the String hop lets Jackson convert straight from the object to its 
> in-memory form (object to tree to object for the clone, object to tree for 
> the diff). This avoids one full serialization to text plus the matching 
> parse, reducing allocations and CPU on the per-reconcile clone path. The 
> clone is the meaningful win given how often it runs. The diff change is a 
> consistency cleanup with negligible runtime effect.
> The change is behavior preserving for the CRD and Fabric8 model types 
> involved, which are JSON-native by design and already round-tripped through 
> JSON by Kubernetes. Existing reconciler and diff tests cover the affected 
> code.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to