-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add mbstring dependency to composer.json #561
Conversation
I don't contest that Parsedown should declare the dependencies it uses, but I wonder whether we have an opportunity to make Parsedown a little more compatible here. Given that we only use Of course, in the current version this dependency should be explicit. I just wonder whether a better solution would be to support vanilla PHP instead of declaring a dependency that just makes Parsedown a little faster? |
The problem is not code complexity, but performance. The polyfill takes 38 times (!) longer than native And there's a second catch: Even when using the polyfill we still require the Parsedown is a library, not an end-user application. We should leave this decision up to (1) the application developer (as soon as they require the polyfill the If you don't have native |
I think the performance impact doesn't really matter, because the performance impact would only be felt if the slow polyfill implementation was actually used. If i.e. If don't have mbstring then Parsedown would be slower, but would at least work. If you do have mbstring installed then there is no difference. Would be something like protected static function mb_strlen(string $s, $enc = null)
{
static $polyfillNeeded;
if (!isset($polyfillNeeded)) { $polyfillNeeded = !function_exists('mb_strlen'); }
return $polyfillNeeded ? self::slower_mb_strlen($s, $enc) : mb_strlen($s, $enc);
} This would still give the end user a decision: if they want to (and can?) install mbstring then Parsedown will be faster, if not then at least it'll still work. You do make a good point about iconv also being an extension though (albeit being a core/default one), so relying on this instead of mbstring probably doesn't gain too much. Maybe (as you say) it is just simpler to require the dependency we actually need, not having mbstring enabled is a pretty weird situation anyway ;p (and probably doesn't happen too often?) |
One in a million or something like that? This problem virtually doesn't exist for production servers. We recently learned that there are millions of Parsedown installations out there - and there are exactly two Issues about this, this one count in 😆
Exactly.
Simply put, it's opt-in vs. opt-out. I'd strongly vote for opt-in - not because I think that this makes Parsedown slower for users with native |
Parsedown requires PHP's
mbstring
extension due toparsedown/Parsedown.php
Line 170 in d638fd8
Parsedown never worked without the
mbstring
extension and users were experiencing PHP errors. Most PHP installations havembstring
enabled (even though it's not one of PHP's default extensions, it's a default extension on virtually any Linux distribution), so IMO there's no need for action here besides making this implicit dependency explicit. Users which can't installmbstring
on their platform can still use a polyfill like https://github.com/symfony/polyfill-mbstring, but since it's comparibly slow and users should rather install thembstring
extension whenever possible, we shouldn't make the polyfill the default. Letting users know about this is IMO the best way to deal with it.Also see #541 - what should be closed IMO