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

Editor slowdown when resolving due to translations in assertions #459

Closed
Selenyhr opened this issue Jan 26, 2024 · 1 comment
Closed

Editor slowdown when resolving due to translations in assertions #459

Selenyhr opened this issue Jan 26, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Selenyhr
Copy link
Contributor

Selenyhr commented Jan 26, 2024

Describe the bug

For the game I work on, I decided on using Dialogue Manager to help me do the variable substitutions in parts of my UI.
For this, I passed the parser a line, and then passed the result to create a DialogueLine:

var parse_result: DialogueManagerParseResult = DialogueManagerParser.parse_string(": {entry_hint} [ID:hint_{id}]".format({"entry_hint": tr(entry.hint, &"galleries.images.hints"), "id": entry.cg_resource_uri}), "")
var line: DialogueLine = await DialogueManager.create_dialogue_line(parse_result.lines["1"], [])

This is done for a UI with a 4x3 grid, so 12 calls are done per page.

However when changing the page, there is a big hiccup which seems to be of about 300ms, due to the DialogueConstants.translate calls:
image

It seems that when using a debug run, the DialogueConstants.translate calls within the 6 assert(limit < 1000, translate(xxx)) are done, and due to the way the function works, it slows down the game.

I suspect this also may slow down the editor when using the plugin normally.


Affected version

Hardware: i5-12600K, 16GB RAM, RX 6900 XT, 2TB PCIe 4 NVMe SSD


To Reproduce

Make a new project, ask the parser to parse a string on the fly, then create the DialogueLine associated with it and run it with in debug mode:

var parse_result: DialogueManagerParseResult = DialogueManagerParser.parse_string(": Some string [ID:some_line_id]", "")
var line: DialogueLine = await DialogueManager.create_dialogue_line(parse_result.lines["1"], [])

The more calls are done like this, the worst the issue becomes, due to the 6 assert calls that are done to see if something went wrong, and the hard loop limits are reached.


Expected behavior

One of the following:

  • Improve the way the translate function is to make use of some sort of cache, and speed it up ;
  • The translate call is evaluated only when needed, which would make writing ifs around the assert()s the easiest solution.

If you would like me to make a PR, just tell me which route you'd like to take :) for the time being I'll add ifs around the assert()s so I no longer have the 300ms hiccups :)

@Selenyhr Selenyhr added the bug Something isn't working label Jan 26, 2024
@nathanhoad
Copy link
Owner

I wasn't able to replicate the slowdown that you're experiencing but I have moved all runtime asserts to be behind conditional checks to stop early evaluation of the message expressions.

I'd also suggest you use Expressions for evaluating stuff instead of trying to parse individual lines with Dialogue Manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants