r/programmingcirclejerk • • Feb 25 '20

it is currently faster to launch PHP to execute a regex than it is to use std::regex

https://cor3ntin.github.io/posts/abi/
183 Upvotes

32 comments sorted by

92

u/sebamestre Feb 26 '20

/uj Dont see how this is a jerk. Regex in C++ is just plain bad, and the title is actually true

59

u/r2d2_21 groks PCJ Feb 26 '20

Sometimes, truth is the best source for a jerk.

21

u/LasseF-H It's GNU/PCJ, or as I call it, GNU + PCJ Feb 26 '20

They hated jesus because he told them the truth.

46

u/qqwy Feb 26 '20

I mean... he's not wrong.

And both regex implementations are equally unsuitable for Unicode as well!

22

u/Exepony log10(x) programmer Feb 26 '20

Perl has the only good Unicode implementation.

/uj Perl has the only good Unicode implementation.

20

u/qqwy Feb 26 '20

/unjerk Unfortunately, I think you are incorrect: https://blog.burntsushi.net/ripgrep/

/jerk Rustaceons unite!

9

u/[deleted] Feb 26 '20 edited Feb 26 '20

What does grep have to do with unicode support?

Also GNU grep supports arbitrary encoding via LC_CTYPE.

18

u/fp_weenie Zygohistomorphic prepromorphism Feb 26 '20

The regex crate, written by Andrew Gallant, has unicode support and is good.

8

u/edapa Feb 27 '20

unjerk!("The regex crate only really has utf8 support. It doesn't understand utf32_le or utf16")

0

u/[deleted] Feb 26 '20

[deleted]

5

u/[deleted] Feb 26 '20

You mean POSIX

3

u/Benjamin-FL Feb 28 '20

SPEED!!!

std::unjerk(move || {

Rust's regex crate is very fast, but is also limited to recognizing languages that are actually regular, unlike most regex libraries. This means, among other things, no backreferences, and no lookaround. So, like pretty much everything in programming, it's a tradeoff.

});

1

u/pusillanimouslist loves Java Feb 28 '20

As always, Rust has done it best.

73

u/mcorah Code Artisan Feb 26 '20

The first time I tried using std::regex, the method I wanted to use wasn't implemented. It didn't even throw an error...

50

u/HINDBRAIN Considered Harmful Feb 26 '20

Going into the source code of a fucky library and seeing a //TODO followed by returning an empty list is a terrible feeling.

23

u/fp_weenie Zygohistomorphic prepromorphism Feb 26 '20

how pragmatic!

33

u/logicchains Feb 26 '20

Security consultant here. This problem wouldn't happen if not for the foul influence of generics. Not only do generics cause countless security vulnerabilities, they force ugly symbol names upon unsuspecting binaries. Not so nice when your pretty template function turns into _ZNK3MapI10StringName3RefI8GDScriptE10ComparatorIS0_E16DefaultAllocatorE3hasERKS0_, is it?

In a practical language like C (or my favourite, Go), there's no generics so functions have nice simple names like "maxInt8", directly controlled by the programmer. This means means the symbols don't get renamed unless the programmer chooses to, so there's no risk of nasty, insecure ABI breakage like described in the article.

10

u/dreamin_in_space Feb 26 '20

/uj I forgot what sub we were on.. SMH.

56

u/[deleted] Feb 26 '20

Yeah, but T_PAAMAYIM_NEKUDOTAYIM

4

u/snoyberg I've never used generics and I’ve never missed it. Feb 26 '20

פעמיים נקודותיים

54

u/[deleted] Feb 26 '20

[removed] — view removed comment

2

u/StunningStore Feb 26 '20

Yuri, what's going on big guy? I just watched you trip my wife. I saw you do it.

1

u/YuriKlastalov Considered Harmful Feb 26 '20

Do you really wanna sit here and go through the rigamaroo?

1

u/StunningStore Feb 26 '20

Nick. I didnt travel through three states so you could trip my field hockey of a wife through a table.

10

u/CodeReclaimers Do you do Deep Learning? Feb 26 '20

This is good for C++.

/uj

What is this, a Buttcoin/PCJ crossover episode?

8

u/[deleted] Feb 26 '20

Who launches PHP to execute a regex? Everyone knows the correct way is to call Perl from libC like Apple was doing.

8

u/hexane360 type astronaut Feb 26 '20

From a related twitter discussion:

What makes C++ so hard is that there are 50 ways to solve any given problem and 45 of them are bad in non-obvious ways.

1

u/camelCaseIsWebScale Just spin up O(n²) servers Feb 27 '20

You know guys? Do you know a single industry strength program that Bjarne Stroustrup wrote? PHP randaf rote his_personalHomepAge in $PHP

-1

u/camelCaseIsWebScale Just spin up O(n²) servers Feb 27 '20 edited Feb 28 '20

It is about "Launching PHP to execute a regex" not "Launching PHP and executing a regex". Apparently the regex was somewhat heavy, bloated and GNU-esque.

or as I've recently taken to calling it, GNU+heavy, GNU+bloated and GNU plus GNU-esque.

0

u/[deleted] Feb 26 '20

[deleted]

42

u/hedgehog1024 Rust apologetic Feb 26 '20

In short: C double plus good's stable ABI is bad

19

u/hedgehog1024 Rust apologetic Feb 26 '20

Or was it orange crab who is bad? Shit, I can't recall.

11

u/THICC_DICC_PRICC helped pollute the computing environment Feb 26 '20

C double plus is too many syllables and not 10x, C pee pee is more efficient