-
Notifications
You must be signed in to change notification settings - Fork 2
Decrease RAM Usage and index load and build times with Marisa Trie + Speed, Concurrency, and Unit Tests #9
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
Open
Sheshank-s
wants to merge
12
commits into
davidmcclure:master
Choose a base branch
from
Sheshank-s:trie
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
62ca652
loading code with sqlite3 + new unit tests + new speed testing
Sheshank-s 6dab318
Revert "loading code with sqlite3 + new unit tests + new speed testing"
Sheshank-s 0380cd8
two level dict => marisa trie
Sheshank-s 9bc934d
combine all trie files into one
Sheshank-s 19e557f
bug fix
Sheshank-s 59a46b3
separate tries per index
Sheshank-s 81d3bb6
some speed optimizations
Sheshank-s 4963a3f
use raw json
Sheshank-s 6eacada
remove unused imports
Sheshank-s cfff9b2
cleanup
Sheshank-s a2f4915
Update tests to match new match output format
Sheshank-s 0ad83ae
Resolve merge request reviews
Sheshank-s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ PyYAML = "*" | |
| Shapely = "*" | ||
| numpy = "*" | ||
| scipy = "*" | ||
| marisa_trie = "*" | ||
|
|
||
| [dev-packages] | ||
|
|
||
|
|
||
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| from multiprocessing import Pool | ||
| from litecoder.usa import USCityIndex, USStateIndex | ||
| import time | ||
|
|
||
| NUM_PROCESSES = 4 | ||
|
|
||
| # Load 50 test city lookups | ||
| with open("tests/runtime/test_city_lookups.txt", "r") as lookups_file: | ||
| city_tests = lookups_file.read().splitlines() | ||
|
|
||
| # Increase the number of lookups for the speed test if necessary | ||
| for x in range (10): | ||
| city_tests += city_tests | ||
| num_tests_per_process = len(city_tests) | ||
| num_tests = NUM_PROCESSES * num_tests_per_process | ||
|
|
||
| # Load USCityIndex | ||
| city_idx = USCityIndex() | ||
| city_idx.load() | ||
|
|
||
|
|
||
| def lookup_cities(process_num): | ||
| print ('Process {}: looking up {} cities'.format(process_num, num_tests_per_process)) | ||
| start_time = time.time() | ||
| for city in city_tests: | ||
| city_idx[city] | ||
| ms = 1000*(time.time() - start_time) | ||
| print("Process {}: finished, took {}ms @ {} ms/lookup!".format(process_num, ms, float(ms/num_tests_per_process))) | ||
|
|
||
| if __name__ == '__main__': | ||
| print("Looking up {} cities on {} processes...".format(num_tests, NUM_PROCESSES)) | ||
| start_time = time.time() | ||
| with Pool(5) as p: | ||
| p.map(lookup_cities, range(1, NUM_PROCESSES+1)) | ||
| ms = 1000*(time.time() - start_time) | ||
| print("Fully finished: took {}ms @ {} ms/lookup!".format(ms, float(ms/num_tests))) | ||
|
|
||
| print() | ||
| print("Looking up all {} cities on one process...".format(num_tests), end="") | ||
| start_time = time.time() | ||
| for i in range(NUM_PROCESSES): | ||
| for city in city_tests: | ||
| city_idx[city] | ||
| ms = 1000*(time.time() - start_time) | ||
| print("finished: took {}ms @ {} ms/lookup!".format(ms, ms/num_tests)) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from litecoder.usa import USCityIndex, USStateIndex | ||
| import time | ||
|
|
||
| print("Loading USCityIndex... ", end="") | ||
| start_time = time.time() | ||
| city_idx = USCityIndex() | ||
| city_idx.load() | ||
| print("finished: {}s!".format(time.time() - start_time)) | ||
|
|
||
| # Load 50 test city lookups | ||
| with open("test_city_lookups.txt", "r") as lookups_file: | ||
| city_tests = lookups_file.read().splitlines() | ||
|
|
||
| # Increase the number of lookups for the speed test if necessary | ||
| for x in range (5): | ||
| city_tests += city_tests | ||
| num_tests = len(city_tests) | ||
| print("measuring time for {} cities... ".format(num_tests), end="") | ||
| start_time = time.time() | ||
| for city in city_tests: | ||
| city_idx[city] | ||
| ms = 1000*(time.time() - start_time) | ||
| print("finished: took {}ms at {} ms/lookup!".format(ms, float(ms/num_tests))) | ||
|
|
||
| print("Loading USStateIndex... ", end="") | ||
| start_time = time.time() | ||
| state_idx = USStateIndex() | ||
| state_idx.load() | ||
| print("finished: {}s!".format(time.time() - start_time)) | ||
|
|
||
| # Load 50 test state lookups | ||
| with open("test_state_lookups.txt", "r") as lookups_file: | ||
| state_tests = lookups_file.read().splitlines() | ||
|
|
||
| # Increase the number of lookups for the speed test if necessary | ||
| for x in range (5): | ||
| state_tests += state_tests | ||
| num_tests = len(state_tests) | ||
| print("measuring time for {} states... ".format(num_tests), end="") | ||
| start_time = time.time() | ||
| for state in state_tests: | ||
| state_idx[state] | ||
| ms = 1000*(time.time() - start_time) | ||
| print("finished: took {}ms at {} ms/lookup!".format(ms, float(ms/num_tests))) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.