fhir-crucible / testscript-engine

Ruby FHIR TestScript execution engine
Apache License 2.0
5 stars 2 forks source link

Bug Fix: Slow Load Time #45

Closed ms-k1ngk0ng closed 2 years ago

ms-k1ngk0ng commented 2 years ago

Summary

Addressed the 12-14 second load-up time when running the engine locally using the ruby command ruby run.rb.

New behavior

Load up occurs in a little under 2 seconds now.

Code changes

For whatever reason, the culprit for slow load-up time was singularly the fhir_client gem. It took forever to search the environment for the gem. Now, the path of that gem is found using linux commands and appended to the global $LOAD_PATH variable to reduce the search time. I found a gem called faster_require that I imagine does the same thing for every gem needed, but I think my hack works for now -- plus I think investing any more time into this might be fruitless.

Also, moved the CLI code into its own module to circumvent the need to maintain it in two places -- it was previously being repeated in the bin executable and run.rb.

Testing guidance

Pull down the changes and run ruby run.rb. Observe noticeable speed-up.

jhlee-mitre commented 2 years ago

I tested this PR on my end and the results were same in different conditions:

Is there anything need to apply the changes other than pulling the code from the branch?

ms-k1ngk0ng commented 2 years ago

@jhlee-mitre Could you use the Benchmark gem to locate which require __some_gem__ statement is taking the longest? My assumption is that you're running into the same issue I faced with fhir_client, but for some other gem. Which is incredibly annoying.

jhlee-mitre commented 2 years ago

@jhlee-mitre Could you use the Benchmark gem to locate which require __some_gem__ statement is taking the longest? My assumption is that you're running into the same issue I faced with fhir_client, but for some other gem. Which is incredibly annoying.

Below is the benchmark result and it is obvious that fhir_client is the one slow.

puts Benchmark.measure {require 'pry-nav'} puts Benchmark.measure {require 'fhir_client'} puts Benchmark.measure {require_relative 'testscript_engine/testscript_runnable'} puts Benchmark.measure {require_relative 'testscript_engine/message_handler'} puts Benchmark.measure {require_relative 'testscript_engine/cli'}

0.096005 0.044182 0.150739 ( 0.166184) 4.528002 1.027228 5.555230 ( 5.614234) 0.014796 0.006370 0.021166 ( 0.021844) 0.000008 0.000001 0.000009 ( 0.000008) 0.000319 0.000131 0.000450 ( 0.000492)

ms-k1ngk0ng commented 2 years ago

@jhlee-mitre Rebased off of main. Try running as the README now directs --- bundle exec bin/testscript_engine. This should yield some major improvements, and also removes the need for the run.rb script.

jhlee-mitre commented 2 years ago

@jhlee-mitre Rebased off of main. Try running as the README now directs --- bundle exec bin/testscript_engine. This should yield some major improvements, and also removes the need for the run.rb script.

I tested it and got a lot faster less than 2 second for loading libraries. Awesome!