fix: reduce memory footprint when loading TLDs#362
Merged
yozachar merged 1 commit intopython-validators:masterfrom Apr 4, 2024
Merged
fix: reduce memory footprint when loading TLDs#362yozachar merged 1 commit intopython-validators:masterfrom
yozachar merged 1 commit intopython-validators:masterfrom
Conversation
bmwiedemann
pushed a commit
to bmwiedemann/openSUSE
that referenced
this pull request
Apr 26, 2024
https://build.opensuse.org/request/show/1170193 by user mia + anag+factory - Update to 0.28.1 * fix: reduce memory footprint when loading TLDs gh#python-validators/validators#362 * fix: rfc cases in the domain validator gh#python-validators/validators#367 * chore: documentation maintenance gh#python-validators/validators#368
Contributor
|
This significantly slows down TLD lookup. Opening a file and scanning it for every email validation is very inefficient. Is the memory footprint that much of a concern? Would you be open to changing it back to something like this, which is 10 times faster? _iana_tld_set = None
def _iana_tld():
global _iana_tld_set
if _iana_tld_set:
return _iana_tld_set
with Path(__file__).parent.joinpath("_tld.txt").open() as tld_f:
_ = next(tld_f)
_iana_tld_set = {line.strip() for line in tld_f}
return _iana_tld_set |
Collaborator
Author
That's true for repeated validations.
Yes, if the file is too, large and/or, system memory is insufficient. What about a It will load and store the TLDs once. If that method isn't called, it'll lookup the file every time. Associate that method with a A PR is welcome. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.