mulesoft-consulting / json-logger

Drop-in replacement for default Mule Logger that outputs a JSON structure based on a predefined JSON schema
MIT License
68 stars 213 forks source link

Performance issue due to redundant serialization/deserialization and recursive iterations #28

Open cut-to-the-cheese opened 3 years ago

cut-to-the-cheese commented 3 years ago

Current set of operations:

When a property within the JSON is masked, these operations are performed:

  1. The incoming payload in the json-logger component is deserialized from InputStream into a JSON object.
  2. A deep copy of the JSON object is created.
  3. The masking is applied by recursively iterating over the deep copy.

Issue:

There is an implicit recursive iteration in steps 1 and 2, and an explicit iteration in step 3.

Fix:

Use a custom deserializer for converting the incoming payload of the InputStream type to a JSON object. During the tokenization/detokenization, apply the mask in place and thereby eliminating the need for steps 2 and 3 resulting in a performance gain of up to a factor of 3.

skuller commented 3 years ago

this is brilliant! Please reach out to @juancavallotti and @DavoCoder to further evaluate the suggested solution!

best,

Andres

cut-to-the-cheese commented 3 years ago

@skuller thank you for the update. I will check with our team for best path forward.