Re: [FAB-17598] Improve the efficiency of viperutil.EnhancedExactUnmarshal

Matthew Sykes

In my experience, Jira issues age more like a weathered parking lot than a fine wine....

The excessive times are most easily observed when running with the race detector enabled and this is how we run the tests in CI.
Notice that the version run with the race detector takes 7 times longer.

Regardless, the implementation of `EnhancedExactUnmarshal` is extremely inefficient as it makes multiple passes over every configuration element using a combination of the yaml, viper, and mapstructure packages. It's also an example of code that relies on buggy behavior as a feature as it only works because of a bug in viper's case sensitivity / preservation behavior from a very, very old version of viper.

So, as Brett said, we added a cache to ensure we would not repeatedly unmarshal the same configuration document multiple times in test. That reduced our unit test execution times by ~20 minutes. That reduced the urgency of improving the implementation but not the need.

Hope that helps.

On Wed, May 20, 2020 at 11:24 AM Brett T Logan <brett.t.logan@...> wrote:
This Jira is to improve the overall performance of the EnhancedExactUnmarshal. You won't be able to reproduce the slow times anymore as a change was push to cache the result of the call to EnhancedExactUnmarshal and pull from that cache rather than unmarshal it every time. I can try to find the PR where those changes were made so you can see the caching mechanism.
I assume we would still want to improve the performance of this call as the cache is a workaround to the poor performance, but I'll defer to Matt on that question.
Brett Logan
Software Engineer, IBM Blockchain
Phone: 1-984-242-6890
----- Original message -----
From: "Nicholas Basker" <nbasker@...>
Sent by: fabric@...
To: fabric@...
Subject: [EXTERNAL] [Hyperledger Fabric] [FAB-17598] Improve the efficiency of viperutil.EnhancedExactUnmarshal
Date: Wed, May 20, 2020 10:06 AM
New comer to HL fabric, starting out by building, running and understanding the unit and integration tests. Picked the help-wanted JIRA issue below
Just took a sample set of the following tests peer.TestCreateChannel, genesisconfig.TestLoadProfile.func1. Tried to reproduce as shown below, it seems to be completing in milliseconds as opposed ~5seconds below. I tried doing "make unit-test" and "make integration-test" but unable to get the issue.
Possibly am missing something in my repro steps, any pointers on steps to repro would be helpful.
(Tried using the recommended method of TEST_PKGS=" unit-test, but the run was cached inspite of giving -count=1 in GO_TAGS, then resorted to the method below)

nb@~/Documents/$ go test -v | grep TestCreateChannel

=== RUN   TestCreateChannel

--- PASS: TestCreateChannel (0.29s)

nb@~/Documents/$ go test -v -count=1 | grep TestLoadProfile

=== RUN   TestLoadProfile

=== RUN   TestLoadProfile/SampleDevModeKafka

=== RUN   TestLoadProfile/SampleDevModeSolo

=== RUN   TestLoadProfile/SampleSingleMSPChannel

=== RUN   TestLoadProfile/SampleSingleMSPKafka

=== RUN   TestLoadProfile/SampleSingleMSPSolo

--- PASS: TestLoadProfile (0.35s)

    --- PASS: TestLoadProfile/SampleDevModeKafka (0.33s)

    --- PASS: TestLoadProfile/SampleDevModeSolo (0.00s)

    --- PASS: TestLoadProfile/SampleSingleMSPChannel (0.00s)

    --- PASS: TestLoadProfile/SampleSingleMSPKafka (0.00s)

    --- PASS: TestLoadProfile/SampleSingleMSPSolo (0.00s)

=== RUN   TestLoadProfileWithPath

=== RUN   TestLoadProfileWithPath/SampleDevModeKafka

=== RUN   TestLoadProfileWithPath/SampleDevModeSolo

=== RUN   TestLoadProfileWithPath/SampleSingleMSPChannel

=== RUN   TestLoadProfileWithPath/SampleSingleMSPKafka

=== RUN   TestLoadProfileWithPath/SampleSingleMSPSolo

--- PASS: TestLoadProfileWithPath (0.02s)

    --- PASS: TestLoadProfileWithPath/SampleDevModeKafka (0.00s)

    --- PASS: TestLoadProfileWithPath/SampleDevModeSolo (0.00s)

    --- PASS: TestLoadProfileWithPath/SampleSingleMSPChannel (0.00s)

    --- PASS: TestLoadProfileWithPath/SampleSingleMSPKafka (0.00s)

    --- PASS: TestLoadProfileWithPath/SampleSingleMSPSolo (0.00s)


Matthew Sykes

Join to automatically receive all group messages.