Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize performance of LG evaluation #3327

Merged
merged 2 commits into from
Feb 4, 2020
Merged

Optimize performance of LG evaluation #3327

merged 2 commits into from
Feb 4, 2020

Conversation

Danieladu
Copy link
Collaborator

@Danieladu Danieladu commented Feb 3, 2020

close: #3297

Today, every time a free LG text like "@{welcome}" is evaluated by creating a new "anonymous template" to wrap this free text, and create a temporary LG file with the new content = original content + new anonymous template, for evaluation.

This is not performance friendly. In this pr, we just parse the additional part, so that there is no need to reparse the original content.

@coveralls
Copy link
Collaborator

coveralls commented Feb 3, 2020

Pull Request Test Coverage Report for Build 103269

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 96 unchanged lines in 5 files lost coverage.
  • Overall coverage decreased (-3.6%) to 78.027%

Files with Coverage Reduction New Missed Lines %
/libraries/Microsoft.Bot.Builder.LanguageGeneration/Range.cs 4 68.75%
/libraries/Microsoft.Bot.Builder.LanguageGeneration/CustomizedMemory.cs 5 69.7%
/libraries/Microsoft.Bot.Builder.LanguageGeneration/LGFile.cs 14 85.56%
/libraries/Microsoft.Bot.Builder.LanguageGeneration/Evaluator.cs 29 91.74%
/libraries/Microsoft.Bot.Builder.LanguageGeneration/Expander.cs 44 84.24%
Totals Coverage Status
Change from base Build 103006: -3.6%
Covered Lines: 21157
Relevant Lines: 27115

💛 - Coveralls

@fuselabs
Copy link
Collaborator

fuselabs commented Feb 3, 2020

✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.Luis.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.QnA.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.ApplicationInsights.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Azure.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Dialogs.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Integration.ApplicationInsights.Core.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Integration.AspNet.Core.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.TemplateManager.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Testing.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Configuration.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Connector.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Schema.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Streaming.dll compared against version 4.6.3

@boydc2014
Copy link
Contributor

Looks good, one more thing i have is can we measure\profile this change, see how much we improved.

Some suggestions to profile

  1. compare the time used of finishing all tests, make sure you run it multiple times to warm up
  2. compare the time used of finishing one specific time
  3. compare the time used of one single Evaluate method, perhaps in debug mode in VS and check cpu time?
  4. ChrisMc also mentioned a way to profile in the email, please try that if possible.

@fuselabs
Copy link
Collaborator

fuselabs commented Feb 3, 2020

✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.Luis.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.QnA.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.ApplicationInsights.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Azure.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Dialogs.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Integration.ApplicationInsights.Core.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Integration.AspNet.Core.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.TemplateManager.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Testing.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Configuration.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Connector.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Schema.dll compared against version 4.6.3
✔️ No Binary Compatibility issues for Microsoft.Bot.Streaming.dll compared against version 4.6.3

@Danieladu
Copy link
Collaborator Author

Danieladu commented Feb 3, 2020

Looks good, one more thing i have is can we measure\profile this change, see how much we improved.

Some suggestions to profile

  1. compare the time used of finishing all tests, make sure you run it multiple times to warm up
  2. compare the time used of finishing one specific time
  3. compare the time used of one single Evaluate method, perhaps in debug mode in VS and check cpu time?
  4. ChrisMc also mentioned a way to profile in the email, please try that if possible.
  1. Before optimization, the time used of finishing all adaptive tests is 45s,
    After optimization, the time is 15s.
  2. Before optimization, the time used of Evaluate with 100 iterations is 11s,
    After optimization, the time is 5s.
  3. for the solution provided by ChrisMc, I always get a 401 error when calling luis's api. I will try it later.

@boydc2014
Copy link
Contributor

Looks good, one more thing i have is can we measure\profile this change, see how much we improved.
Some suggestions to profile

  1. compare the time used of finishing all tests, make sure you run it multiple times to warm up
  2. compare the time used of finishing one specific time
  3. compare the time used of one single Evaluate method, perhaps in debug mode in VS and check cpu time?
  4. ChrisMc also mentioned a way to profile in the email, please try that if possible.
  1. Before optimization, the time used of finishing all adaptive tests is 45s,
    After optimization, the time is 15s.
  2. Before optimization, the time used of Evaluate with 100 iterations is 11s,
    After optimization, the time is 5s.
  3. for the solution provided by ChrisMc, I always get a 401 error when calling luis's api. I will try it later.

Looks good. One more thing is, it would be great if we put more context in 'Description' of this PR, for example,

  • if it's a bug fix, you might want to list root cause + how it's fixed + potential impact if any
  • if it's a feature, you might want to list the description of the feature, how the users will benefit or be impacted.
  • if it's a perform tuning, (you can figure it out).

Anyhow, more context help both you and reviewers to have a better context


var newLgFile = LGParser.ParseText(newContent, lgFile.Id, lgFile.ImportResolver);
return newLgFile.EvaluateTemplate(fakeTemplateId, scope);

var allTemplates = lgFile.AllTemplates.Union(newLgFile.AllTemplates).ToList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't you precompute this and only redo when new templates are added?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this newLgFile is computed from the parameter inlineStr, so we can't pre-compute it. What we can do is to cache this string, to avoid re-compute, but based on the profiling result, not much improvement here, because the inlineStr is very small. So this is good enough for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize performance of LG evaluation
5 participants