Paul C. Anagnostopoulos via llvm-dev
2020-Oct-28 16:56 UTC
[llvm-dev] StringSwitch efficiency
At what point should I consider changing from a StringSwitch construct to something more efficient? TableGen has a few of them. In particular, the switch for looking up a bang operator has about 40 cases, all short strings. One trivial improvement would be to split it into two StringSwitch's based on the first letter of the operator name.
On Wed, Oct 28, 2020 at 9:56 AM Paul C. Anagnostopoulos via llvm-dev < llvm-dev at lists.llvm.org> wrote:> At what point should I consider changing from a StringSwitch construct to > something more efficient? TableGen has a few of them. In particular, the > switch for looking up a bang operator has about 40 cases, all short strings. > > One trivial improvement would be to split it into two StringSwitch's based > on the first letter of the operator name. >If that improves performance, then it sounds like a bug/area for improvement in StringSwitch itself, perhaps? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201028/e0d70cec/attachment.html>
Paul C. Anagnostopoulos via llvm-dev
2020-Oct-28 18:09 UTC
[llvm-dev] StringSwitch efficiency
StringSwitch just uses a series of Case functions that compare the target against each case string. Once the target is matched, the remaining Case functions bypass the comparison. One way or the other, it goes through all the Case's. I don't think there is any way to optimize this. Does anyone know if the compiler does something clever? At 10/28/2020 12:58 PM, David Blaikie wrote:>On Wed, Oct 28, 2020 at 9:56 AM Paul C. Anagnostopoulos via llvm-dev <<mailto:llvm-dev at lists.llvm.org>llvm-dev at lists.llvm.org> wrote: >At what point should I consider changing from a StringSwitch construct to something more efficient? TableGen has a few of them. In particular, the switch for looking up a bang operator has about 40 cases, all short strings. > >One trivial improvement would be to split it into two StringSwitch's based on the first letter of the operator name. > >If that improves performance, then it sounds like a bug/area for improvement in StringSwitch itself, perhaps?Â