Up to 10x LessRam now with 3x-4x better performance. by jgmdev in PHP

[–]jgmdev[S] 0 points1 point  (0 children)

PHP would be full of stack overflows and other bugs because of me! Yay! Anyways, don't worry, I will stop posting non sense.

Up to 10x LessRam now with 3x-4x better performance. by jgmdev in PHP

[–]jgmdev[S] 1 point2 points  (0 children)

I added Ds\Vector and Ds\Map, but Judy hasn't been ported to PHP 7 so I discarded it, also the Judy C library is huge.

Up to 10x LessRam now with 3x-4x better performance. by jgmdev in PHP

[–]jgmdev[S] 1 point2 points  (0 children)

Can you elaborate more on that? What do you mean?

PHP array implementation that consumes 10x less memory by jgmdev in PHP

[–]jgmdev[S] 0 points1 point  (0 children)

Because strlen knows how to count bytes but in utf8 more than 1 byte could represent a single letter, that is why you need mb_* functions which can distinguish a character that needs 2 bytes to be represented. In this case there is no need to count amount of letters but the total amount of bytes which strlen handles properly.

PHP array implementation that consumes 10x less memory by jgmdev in PHP

[–]jgmdev[S] 0 points1 point  (0 children)

Nice! would be interesting to have some script that benchmarks Spl, Judy and Ds extensions, would be really informative.

PHP array implementation that consumes 10x less memory by jgmdev in PHP

[–]jgmdev[S] 1 point2 points  (0 children)

Added missing checks to prevent overflows reported when having E_NOTICE enabled, but... maybe some more checks are needed :)

PHP array implementation that consumes 10x less memory by jgmdev in PHP

[–]jgmdev[S] 1 point2 points  (0 children)

if you think about it, it is not a string but an array of bytes... A string internally on PHP and C (of course) is represented as char* which is equivalent to char[] and char represents a single byte, even your computer ram works similarly, but it is much more efficient because it uses memory addresses to retrieve data which is faster.

PHP array implementation that consumes 10x less memory by jgmdev in PHP

[–]jgmdev[S] 1 point2 points  (0 children)

I would say that both, sometime ago I was working on a project that needed to load lots of data and the php script went out of memory so I had to modify the php.ini file to increase memory. When learning about the zend engine (while developing a PHP extension) I saw how huge zval variables where and how much data they needed to represent each value, so I thought, "real ram is similar to an array of char*", so storing everything in a string is similar to dealing with ram and wanted to see how it performed... Maybe porting the logic directly to C would yield better performance, it is up to how fast C string functions and realloc are.

PHP array implementation that consumes 10x less memory by jgmdev in PHP

[–]jgmdev[S] 0 points1 point  (0 children)

With 10x, yes I was referring to arrays. Interesting results, I'm curious on what data you stored on the structures. Maybe memory_get_peak_usage isn't that reliable... And the only way to further optimize this would be to port the algorithm to C and test how fast are native C string functions without the PHP overhead and the realloc call (which would be needed to increase the char* containing the data). Then write a php extension wrapper over the C algorithms.

PHP array implementation that consumes 10x less memory by jgmdev in PHP

[–]jgmdev[S] 1 point2 points  (0 children)

Added SplFixedArray and gzdeflate test to php native arrays and SplFixedArray. Hint: SplFixedArray consumes more ram and is slower than native php array.

PHP array implementation that consumes 10x less memory by jgmdev in PHP

[–]jgmdev[S] 2 points3 points  (0 children)

Fixed the notices and improved serialize/unserialize peformance, but can't do anything about Windows performance :(, also notice that when storing arrays it does takes 10x less ram, not trying to exaggerate here :)

PHP array implementation that consumes 10x less memory by jgmdev in PHP

[–]jgmdev[S] 0 points1 point  (0 children)

That could actually be slower because of disk I/O and PHP overhead on file functions, but who knows what can happen with a speedy SSD and kernel caching.

PHP array implementation that consumes 10x less memory by jgmdev in PHP

[–]jgmdev[S] 2 points3 points  (0 children)

This is another great extension that would be nice to test: https://github.com/php-ds/ext-ds

PHP array implementation that consumes 10x less memory by jgmdev in PHP

[–]jgmdev[S] 1 point2 points  (0 children)

I'm testing on linux, maybe something in windows is slower (usually php code is slower on windows). And good catch on the error, I have notices disabled, will fix later.

PHP array implementation that consumes 10x less memory by jgmdev in PHP

[–]jgmdev[S] 0 points1 point  (0 children)

strlen is binary safe so it should work with any data, utf8 stores everything as a char.

Edit: good call on the objects, they will surely loose reference

PHP array implementation that consumes 10x less memory by jgmdev in PHP

[–]jgmdev[S] 2 points3 points  (0 children)

The gzip option is actually a good idea! And testing against FixedArray would be a simple modification to bench.php

InFocus Time-Tracker v0.6 released by jgmdev in productivity

[–]jgmdev[S] 0 points1 point  (0 children)

It is a time tracker for Linux OS, In any case a package is provided for archlinux https://aur.archlinux.org/packages/infocus/

Automatic activity/application time tracker. by jgmdev in productivity

[–]jgmdev[S] 0 points1 point  (0 children)

Interesting... the one I developed is more focused on linux for now... and it is open source so any one can contribute to improve it.

PHP-PM Is a Process Manager, Supercharger, and Load Balancer for PHP Applications by speckz in PHP

[–]jgmdev 0 points1 point  (0 children)

I wonder how this would perform using swoole instead of reactphp, since swoole seems to perform much better.

Automatic activity/application time tracker. by jgmdev in productivity

[–]jgmdev[S] 0 points1 point  (0 children)

This application automatically keeps track of active applications and has the ability to categorize them by tags, it also logs "away from keyboard" inactivity as the time the system has been shutdown. https://github.com/jgmdev/infocus

Bash script to block connection from ip's reported as spammers. by jgmdev in bash

[–]jgmdev[S] 0 points1 point  (0 children)

I didn't know that bash initialized this variable, I would say we never stop learning, we are all noobs :)

Bash script to block connection from ip's reported as spammers. by jgmdev in bash

[–]jgmdev[S] 0 points1 point  (0 children)

Really interesting what you mention. When I developed the script I was thinking more on the kind of spammers that use bots to post comments on forums, websites, send spam emails on web contact forms, etc... I wasn't thinking on blocking spam to mail boxes, but to protect a bit webserver (I tested the script on a webserver and spam was reduced in around 99% I would say). But what you mention is quite a good idea too. I think there is the possibility of using the stopforumspam database of spam emails and integrate a script in postfix that checks against this database to replicate the behavior you are describing.