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

std.manifestYamlDoc(object, quote_keys=false) is slow #1019

Open
alexander-svendsen opened this issue Sep 28, 2022 · 3 comments
Open

std.manifestYamlDoc(object, quote_keys=false) is slow #1019

alexander-svendsen opened this issue Sep 28, 2022 · 3 comments

Comments

@alexander-svendsen
Copy link

alexander-svendsen commented Sep 28, 2022

When passing quote_keys=false to the method std.manifestYamlDoc it becomes really slow. Seems like the method checks if the key is safe to use without escaping. Uses the bareSafe method. This takes a lot of time.

Maybe the documentation should be updated to warn the users about it? Or the performance could be improved somehow. Or maybe let the users use force invalid keys without checking to lessen the performance hit?

@sparkprime
Copy link
Contributor

It'd be worth trying to move the following sets out of the function so they don't get generated each time:

      local letters = std.set(std.stringChars('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-/'));
      local digits = std.set(std.stringChars('0123456789'));
      local intChars = std.set(digits + std.stringChars('_-'));
      local binChars = std.set(intChars + std.stringChars('b'));
      local hexChars = std.set(digits + std.stringChars('abcdefx_-'));
      local floatChars = std.set(digits + std.stringChars('e._-'));
      local dateChars = std.set(digits + std.stringChars('-'));
      local safeChars = std.set(letters + floatChars);

And also onlyChars could be rewritten to iterate over strSet and charSet to avoid creating an intermediate set.

@sparkprime
Copy link
Contributor

Do you have a lot of keys in your YAML? Do the keys have a lot of characters?

@alexander-svendsen
Copy link
Author

Nope, the object is not particularly large, or complicated:

      objectName: stuff,
      objectType: stuff2,
      objectAlias: stuff3,
      objectVersion: stuff4

I'm running std.manifestYamlDoc on about 5 such objects. but i noticed it got a lot slower, when using the quote_keys=false

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

No branches or pull requests

3 participants