nishantmehta opened a new pull request, #440:
URL: https://github.com/apache/commons-codec/pull/440

   ## Summary
   
   Three phonetic encoders in the `language` package applied their regular 
expressions via `String.replaceAll`, which **recompiles its regex argument on 
every call**. A single `encode` therefore compiled many `Pattern`s, repeated 
for every input.
   
   This hoists those regexes into `static final Pattern` constants (compiled 
once) and applies them with `Matcher.replaceAll`. The regexes, their order, and 
the replacements are unchanged, so the produced codes are identical.
   
   - **Caverphone2** — ~25 patterns per encode
   - **Caverphone1** — 17 patterns per encode
   - **MatchRatingApproachEncoder** — 9 patterns per encode (`cleanName`'s five 
punctuation regexes + a whitespace-collapse applied three times + a boundary 
whitespace-run in `removeVowels`)
   
   ## Measurement
   
   ThreadMXBean allocation driver, 200k warmed ops:
   
   | encoder | before | after |
   |---------|--------|-------|
   | `Caverphone2.encode` | 19670 B/op | 6304 B/op (−68%) |
   | `Caverphone1.encode` | 14005 B/op | 4672 B/op (−67%) |
   | `MatchRatingApproachEncoder.encode` | ~5800 B/op | ~1800 B/op (−70%) |
   
   ## Testing
   
   `Caverphone1Test`, `Caverphone2Test` and `MatchRatingApproachEncoderTest` 
pass unchanged.
   
   Three commits, one per encoder, in case you prefer to take them separately.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to