coveralls: 
[![Coverage Status](https://coveralls.io/builds/27231648/badge)](https://coveralls.io/builds/27231648)

Coverage decreased (-2.08%) to 97.115% when pulling **86404fb40b1a40f9f71835c2faacf068869e4921 on hotfix/long-word-fix** into **d27baf51c1f1b8fd66fa2fc64d601175b1d63c3c on master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/27231648/badge)](https://coveralls.io/builds/27231648)

Coverage decreased (-2.08%) to 97.115% when pulling **86404fb40b1a40f9f71835c2faacf068869e4921 on hotfix/long-word-fix** into **d27baf51c1f1b8fd66fa2fc64d601175b1d63c3c on master**.

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 10523ac..2d2d947 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,15 @@
 # pyspellchecker
 
+## Version 0.5.3
+* Handle memory issues when trying to correct or find candidates for extremely long words
+
+## Version 0.5.2
+Ensure input is encoded correctly; resolves [#53](https://github.com/barrust/pyspellchecker/issues/53)
+
+## Version 0.5.1
+Handle windows encoding issues [#48](https://github.com/barrust/pyspellchecker/issues/48)
+Deterministic order to corrections [#47](https://github.com/barrust/pyspellchecker/issues/47)
+
 ## Version 0.5.0
 * Add tokenizer to the Spell object
 * Add Support for local dictionaries to be case sensitive
diff --git a/spellchecker/info.py b/spellchecker/info.py
index 4ff8196..5ac2bda 100644
--- a/spellchecker/info.py
+++ b/spellchecker/info.py
@@ -5,7 +5,7 @@ __author__ = "Tyler Barrus"
 __maintainer__ = "Tyler Barrus"
 __email__ = "barrust@gmail.com"
 __license__ = "MIT"
-__version__ = "0.5.2"
+__version__ = "0.5.3"
 __credits__ = ["Peter Norvig"]
 __url__ = "https://github.com/barrust/pyspellchecker"
 __bugtrack_url__ = "{0}/issues".format(__url__)
diff --git a/spellchecker/spellchecker.py b/spellchecker/spellchecker.py
index 589c77b..9aa9763 100644
--- a/spellchecker/spellchecker.py
+++ b/spellchecker/spellchecker.py
@@ -159,6 +159,10 @@ class SpellChecker(object):
         word = ENSURE_UNICODE(word)
         if self.known([word]):  # short-cut if word is correct already
             return {word}
+
+        if not self._check_if_should_check(word):
+            return {word}
+
         # get edit distance 1...
         res = [x for x in self.edit_distance_1(word)]
         tmp = self.known(res)
@@ -186,7 +190,7 @@ class SpellChecker(object):
             w
             for w in tmp
             if w in self._word_frequency.dictionary
-            or not self._check_if_should_check(w)
+            and self._check_if_should_check(w)
         )
 
     def unknown(self, words):
@@ -215,7 +219,7 @@ class SpellChecker(object):
             Returns:
                 set: The set of strings that are edit distance one from the \
                 provided word """
-        word = ENSURE_UNICODE(word).lower()
+        word = ENSURE_UNICODE(word).lower() if not self._case_sensitive else ENSURE_UNICODE(word)
         if self._check_if_should_check(word) is False:
             return {word}
         letters = self._word_frequency.letters
@@ -235,7 +239,7 @@ class SpellChecker(object):
             Returns:
                 set: The set of strings that are edit distance two from the \
                 provided word """
-        word = ENSURE_UNICODE(word).lower()
+        word = ENSURE_UNICODE(word).lower() if not self._case_sensitive else ENSURE_UNICODE(word)
         return [
             e2 for e1 in self.edit_distance_1(word) for e2 in self.edit_distance_1(e1)
         ]
@@ -257,10 +261,11 @@ class SpellChecker(object):
         ]
         return [e2 for e1 in tmp for e2 in self.edit_distance_1(e1)]
 
-    @staticmethod
-    def _check_if_should_check(word):
+    def _check_if_should_check(self, word):
         if len(word) == 1 and word in string.punctuation:
             return False
+        if len(word) > self._word_frequency.longest_word_length + 3:  # magic number to allow removal of up to 2 letters.
+            return False
         try:  # check if it is a number (int, float, etc)
             float(word)
             return False
@@ -281,6 +286,7 @@ class WordFrequency(object):
         "_letters",
         "_tokenizer",
         "_case_sensitive",
+        "_longest_word_length"
     ]
 
     def __init__(self, tokenizer=None, case_sensitive=False):
@@ -289,6 +295,7 @@ class WordFrequency(object):
         self._unique_words = 0
         self._letters = set()
         self._case_sensitive = case_sensitive
+        self._longest_word_length = 0
 
         self._tokenizer = _parse_into_words
         if tokenizer is not None:
@@ -351,6 +358,14 @@ class WordFrequency(object):
                 Not settable """
         return self._letters
 
+    @property
+    def longest_word_length(self):
+        """ int: The longest word length in the dictionary
+
+            Note:
+                Not settable """
+        return self._longest_word_length
+
     def tokenize(self, text):
         """ Tokenize the provided string object into individual words
 
@@ -486,8 +501,11 @@ class WordFrequency(object):
 
     def _update_dictionary(self):
         """ Update the word frequency object """
+        self._longest_word_length = 0
         self._total_words = sum(self._dictionary.values())
         self._unique_words = len(self._dictionary.keys())
         self._letters = set()
         for key in self._dictionary:
+            if len(key) > self._longest_word_length:
+                self._longest_word_length = len(key)
             self._letters.update(key)

Memory Issue for long spellings errors/strings
For testing purposes I have given a word of length 20 and 100, in both the cases my server is giving me ```unable to allocate memory``` and my local machine, which is running on 8GB RAM,  hangs.
diff --git a/tests/spellchecker_test.py b/tests/spellchecker_test.py
index b200d6b..d4433bd 100644
--- a/tests/spellchecker_test.py
+++ b/tests/spellchecker_test.py
@@ -68,8 +68,8 @@ class TestSpellChecker(unittest.TestCase):
         self.assertEqual(spell.known(['sherlock']), {'sherlock'})
         self.assertEqual(spell.known(['holmes']), {'holmes'})
         self.assertEqual(spell.known(['known']), {'known'})
-        self.assertEqual(spell.known(['-']), {'-'})
 
+        self.assertEqual(spell.known(['-']), set())
         self.assertEqual(spell.known(['foobar']), set())
         self.assertEqual(spell.known(['ths']), set())
         self.assertEqual(spell.known(['ergos']), set())
@@ -281,6 +281,29 @@ class TestSpellChecker(unittest.TestCase):
         self.assertEqual(spell.candidates('BB'), {'bob', 'bab'})
         self.assertEqual(spell.correction('BB'), 'bob')
 
+    def test_large_words(self):
+        ''' test checking for words that are clearly larger than the largest dictionary word '''
+        spell = SpellChecker(language=None, distance=2)
+        spell.word_frequency.add('Bob')
+
+        words = ['Bb', 'bb', 'BB']
+        self.assertEqual(spell.unknown(words), {'bb'})
+
+        known_words = ['BOB', 'bOb']
+        self.assertEqual(spell.known(known_words), {'bob'})
+
+        self.assertEqual(spell.correction('bobs'), 'bob')
+        self.assertEqual(spell.correction('bobb'), 'bob')
+        self.assertEqual(spell.correction('bobby'), 'bob')
+        self.assertEqual(spell.word_frequency.longest_word_length, 3)
+        self.assertEqual(spell.correction('bobbys'), 'bobbys')
+
+    def test_extremely_large_words(self):
+        ''' test when a word is just extreamly large '''
+        spell = SpellChecker()
+        horrible_word = 'thisisnotarealisticwordthisisnotarealisticwordthisisnotarealisticwordthisisnotarealisticword'
+        self.assertEqual(spell.correction(horrible_word), horrible_word)
+
     def test_capitalization_when_case_sensitive_true(self):
         ''' test that capitalization affects comparisons '''
         spell = SpellChecker(language=None, case_sensitive=True)

pip install -e .
parse_log_pytest
requirements.txt
coverage coveralls pytest
3.6
requirements/requirements-dev.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
astroid==2.11.7
attrs==22.2.0
certifi==2021.5.30
charset-normalizer==2.0.12
coverage==6.2
coveralls==3.3.1
dill==0.3.4
docopt==0.6.2
idna==3.10
importlib-metadata==4.8.3
iniconfig==1.1.1
isort==5.10.1
lazy-object-proxy==1.7.1
mccabe==0.7.0
packaging==21.3
platformdirs==2.4.0
pluggy==1.0.0
py==1.11.0
pycodestyle==2.10.0
pylint==2.13.9
pyparsing==3.1.4
-e git+https://github.com/barrust/pyspellchecker.git@d27baf51c1f1b8fd66fa2fc64d601175b1d63c3c#egg=pyspellchecker
pytest==7.0.1
requests==2.27.1
tomli==1.2.3
typed-ast==1.5.5
typing_extensions==4.1.1
urllib3==1.26.20
wrapt==1.16.0
zipp==3.6.0

name: pyspellchecker
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - astroid==2.11.7
      - attrs==22.2.0
      - charset-normalizer==2.0.12
      - coverage==6.2
      - coveralls==3.3.1
      - dill==0.3.4
      - docopt==0.6.2
      - idna==3.10
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - isort==5.10.1
      - lazy-object-proxy==1.7.1
      - mccabe==0.7.0
      - packaging==21.3
      - platformdirs==2.4.0
      - pluggy==1.0.0
      - py==1.11.0
      - pycodestyle==2.10.0
      - pylint==2.13.9
      - pyparsing==3.1.4
      - pytest==7.0.1
      - requests==2.27.1
      - tomli==1.2.3
      - typed-ast==1.5.5
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - wrapt==1.16.0
      - zipp==3.6.0
prefix: /opt/conda/envs/pyspellchecker

tests/spellchecker_test.py::TestSpellChecker::test_large_words tests/spellchecker_test.py::TestSpellChecker::test_word_known
tests/spellchecker_test.py::TestSpellChecker::test_add_word tests/spellchecker_test.py::TestSpellChecker::test_adding_unicode tests/spellchecker_test.py::TestSpellChecker::test_bytes_input tests/spellchecker_test.py::TestSpellChecker::test_candidates tests/spellchecker_test.py::TestSpellChecker::test_capitalization_when_case_sensitive_defaults_to_false tests/spellchecker_test.py::TestSpellChecker::test_capitalization_when_case_sensitive_true tests/spellchecker_test.py::TestSpellChecker::test_capitalization_when_language_set tests/spellchecker_test.py::TestSpellChecker::test_checking_odd_word tests/spellchecker_test.py::TestSpellChecker::test_correction tests/spellchecker_test.py::TestSpellChecker::test_edit_distance_invalud tests/spellchecker_test.py::TestSpellChecker::test_edit_distance_one tests/spellchecker_test.py::TestSpellChecker::test_edit_distance_one_property tests/spellchecker_test.py::TestSpellChecker::test_edit_distance_two tests/spellchecker_test.py::TestSpellChecker::test_extremely_large_words tests/spellchecker_test.py::TestSpellChecker::test_import_export_gzip tests/spellchecker_test.py::TestSpellChecker::test_import_export_json tests/spellchecker_test.py::TestSpellChecker::test_load_external_dictionary tests/spellchecker_test.py::TestSpellChecker::test_load_text_file tests/spellchecker_test.py::TestSpellChecker::test_missing_dictionary tests/spellchecker_test.py::TestSpellChecker::test_pop tests/spellchecker_test.py::TestSpellChecker::test_pop_default tests/spellchecker_test.py::TestSpellChecker::test_remove_by_threshold tests/spellchecker_test.py::TestSpellChecker::test_remove_by_threshold_using_items tests/spellchecker_test.py::TestSpellChecker::test_remove_word tests/spellchecker_test.py::TestSpellChecker::test_remove_words tests/spellchecker_test.py::TestSpellChecker::test_spanish_dict tests/spellchecker_test.py::TestSpellChecker::test_tokenizer_file tests/spellchecker_test.py::TestSpellChecker::test_tokenizer_provided tests/spellchecker_test.py::TestSpellChecker::test_unique_words tests/spellchecker_test.py::TestSpellChecker::test_unknown_words tests/spellchecker_test.py::TestSpellChecker::test_word_contains tests/spellchecker_test.py::TestSpellChecker::test_word_frequency tests/spellchecker_test.py::TestSpellChecker::test_word_in tests/spellchecker_test.py::TestSpellChecker::test_word_probability tests/spellchecker_test.py::TestSpellChecker::test_words tests/spellchecker_test.py::TestSpellChecker::test_words_more_complete
spellchecker/info.py spellchecker/spellchecker.py CHANGELOG.md
spellchecker/info.py spellchecker/spellchecker.py CHANGELOG.md