v4 Major performance issues with Phiki / CodeEntry
Package
filament/filament
Package Version
4-alpha8
Laravel Version
12
Livewire Version
3
PHP Version
8.4
Problem description
Phiki has some major performance issues vs client-side highlighting. As a result, the CodeEditor field is very sluggish with medium - large content. The performance hit differs depending on the language but it's there with all of them.
I’m not sure this can really be solved? Caching wouldn't help when highlighting a real-time response (eg. displaying response data straight after the user clicks an action). And I've run into similar issues with Tempest in the past.
The only performant solution might be a client-side library?
Expected behavior
Syntax highlighting should have a minimal effect on render times.
Steps to reproduce
-
Clone repo
-
Run
php artisan migrate:fresh --seed. This will seed example html fromresouces/seed-data/exception.htmlinto aCodemodel. -
Navigate to the Code resource -> view. The following will occur:
- When
CodeEntry::make('code')->grammar(Grammar::Html)is uncommented inCodeInfolist.php, the page will time out. Highlight parsing takes over 30 seconds - When
CodeEntry::make('code')->grammar(Grammar::Json)is uncommented, the page takes 9-10 seconds to load. - When
TextEntry::make('code')is uncommented, the page takes around 1 second to load.
Reproduction repository (issue will be closed if this is not valid)
https://github.com/binaryfire/filament-bug-reproduction
Relevant log output
@binaryfire Just wanted to put a comment here as Phiki is my project. One of the main issues with the package right now is that there are some RegEx compatibility issues between Oniguruma (the engine Shiki and vscode-textmate uses) and PCRE (PHP's RegEx engine).
The slow highlighting speed is likely due to an infinite recursion somewhere inside of a grammar file, caused by one of those "incompatible" patterns.
I'm working on getting Phiki to v2.0 where it will be much more resilient to these problematic grammars, but also translate grammars ahead of time to avoid these sort of issues.
In the meantime, I'd really appreciate it if you could open an issue on the Phiki repo with an example code snippet and the specific grammar so that I can try to determine which part is causing the massive slowdown.
Thanks!
@binaryfire Just wanted to put a comment here as Phiki is my project. One of the main issues with the package right now is that there are some RegEx compatibility issues between Oniguruma (the engine Shiki and
vscode-textmateuses) and PCRE (PHP's RegEx engine).The slow highlighting speed is likely due to an infinite recursion somewhere inside of a grammar file, caused by one of those "incompatible" patterns.
I'm working on getting Phiki to v2.0 where it will be much more resilient to these problematic grammars, but also translate grammars ahead of time to avoid these sort of issues.
In the meantime, I'd really appreciate it if you could open an issue on the Phiki repo with an example code snippet and the specific grammar so that I can try to determine which part is causing the massive slowdown.
Thanks!
@ryangjchandler Thanks for the update. 2.0 sounds promising. I’ll open an issue in the Phiki repo and link the reproduction repo from this one.
I’m assuming there will still be a penalty for parsing in PHP vs client side though? I spun up a custom Filament field using Prism and it was really fast. Do you think 2.0 will be in the same ballpark as JS libraries for large documents (eg. 500+ lines)?
@binaryfire That's the goal, yes. Server-side highlighting prevents a lot of "flash of content" issues that you can run into with client-side highlighters like Prism and Highlight.js.
The performance impact is honestly negligible in most cases. My entire blog runs on Phiki with zero caching and it's faster and prettier than most of those libraries.
The other benefit to using a server-side highlighter is that you don't need to release a new version of Filament with new asset bundles when those packages are updated with new grammars and rules. Phiki would make these changes inside of a minor release which you'd get in your own application by simply running composer update.
I will accept a PR that just "timeboxes" the highlighting process to 50ms or something (is that long enough for most content)? If it times out, we can just render it without highlighting I think. That should be good enough until the issue in the dependency is fixed.
In #17157, users now need to explicitly require a Phiki version when using the code entry. When Ryan is able to improve the performance of the package and release a new major version (with more limited grammars available), you should be able to require it without there needing to be any further updates to the Filament core.
Hey @danharrin, @ryangjchandler could you test this change in Laravel Cloud? We've been hitting timeout issues when trying to use phiki in Cloud (works fine on a $6 DO server though). Getting consistent Maximum execution time of 99 seconds exceeded errors in the Tokenizer - seems like phiki just doesn't play well with Cloud's environment. Curious if making it optional/manual fixes the performance issues there.
[26-Jul-2025 19:29:54 UTC] PHP Fatal error: Maximum execution time of 99 seconds exceeded in /var/www/html/vendor/phiki/phiki/src/Tokenizer.php on line 268
2025-07-26 19:29:55 UTC
ERROR: Maximum execution time of 99 seconds exceeded
class: Symfony\Component\ErrorHandler\Error\FatalError
file: /var/www/html/vendor/phiki/phiki/src/Tokenizer.php:268
2025-07-26 19:30:15 UTC
[26-Jul-2025 19:30:15 UTC] PHP Fatal error: Maximum execution time of 99 seconds exceeded in /var/www/html/vendor/phiki/phiki/src/Tokenizer.php on line 786
2025-07-26 19:30:15 UTC
ERROR: Maximum execution time of 99 seconds exceeded
2025-07-26 19:30:27 UTC
ERROR: Maximum execution time of 99 seconds exceeded
2025-07-26 19:30:27 UTC
[26-Jul-2025 19:30:27 UTC] PHP Fatal error: Maximum execution time of 99 seconds exceeded in /var/www/html/vendor/phiki/phiki/src/Grammar/BeginEndPattern.php on line 44
2025-07-26 19:30:58 UTC
[26-Jul-2025 19:30:58 UTC] PHP Fatal error: Maximum execution time of 99 seconds exceeded in /var/www/html/vendor/phiki/phiki/src/Grammar/ParsedGrammar.php on line 51
2025-07-26 19:30:58 UTC
ERROR: Maximum execution time of 99 seconds exceeded
2025-07-26 19:31:02 UTC
ERROR: Maximum execution time of 99 seconds exceeded
class: Symfony\Component\ErrorHandler\Error\FatalError
file: /var/www/html/vendor/phiki/phiki/src/Tokenizer.php:786
2025-07-26 19:31:02 UTC
[26-Jul-2025 19:31:02 UTC] PHP Fatal error: Maximum execution time of 99 seconds exceeded in /var/www/html/vendor/phiki/phiki/src/Tokenizer.php on line 786
@ManukMinasyan https://github.com/filamentphp/filament/pull/17157 didn’t fix the performance problem. It just requires Phiki to be installed manually.
Serverless environments are more sensitive to issues like this than VPS / bare metal, which is why it’s more noticeable for you on Cloud.
Unfortunately there isn’t much that can be done until Phiki addresses the issue.
@binaryfire If you're on v4 now, please try installing v2.0.0-alpha3 or newer for Phiki and seeing how it goes. I've tested on Cloud and it all seems to be working :)
@binaryfire If you're on v4 now, please try installing
v2.0.0-alpha3or newer for Phiki and seeing how it goes. I've tested on Cloud and it all seems to be working :)
@ryangjchandler Hey mate. Unfortunately I'm still hitting the timeout:
The entry I'm testing with is the HTML of an exception page. You can check out my reproduction repo here: https://github.com/binaryfire/filament-bug-reproduction. Just migrate/seed, then head to the Code resource and try and view the record.
@binaryfire Is this happening locally too?
@ryangjchandler I'm only testing locally atm. But it's basically the same as my as prod environment. Ubuntu 24.04, PHP 8.3, Postgres, Redis. Execution timeout is 30sec.
@binaryfire Could you open an issue on the Phiki repo please with the grammar, theme and text that you're highlighting.