« first day (4061 days earlier)      last day (878 days later) » 
00:00 - 15:0015:00 - 00:00

JRL
3:04 PM
@Danack it's already under "In Discussion" though, as I announced it on the list in August with the explicit note that I planned on it not coming to a vote for months and wanted plenty of time for people to consider and provide feedback since i figured it would be a contentious feature.
i guess i shouldn't call mike a chatterbox, i kind of do that in this channel to some extent
 
yeah.....chatterbox is inaccurate. Egotistical self-aggrandising muppet is probably more accurate.
 
@IluTov which can be circumvented by just requiring a whitespace (or doing lexer sheganigans)
 
you could probably get away with it by using look-ahead(1), but I don't know how PHP's internal lexer works to be honest..
 
JRL
3:23 PM
isn't PHP LL(1)?
 
cmb
LALR(1)
 
My RFC writing abilities, such as they are, are available for the operator overloading effort.
 
JRL
well im about to sleep but i do welcome anyone who wants to contribute
just understand, it may be a sisyphian effort. i went into the project knowing that and being okay with it. :)
 
I had far more fails than passes in the 8.1 cycle. I'm used to it. :-/ Most OSS is specwork, which is shitty, but is how OSS works today.
 
3:49 PM
o/
 
4:06 PM
@Danack ...and? Four day weekend. Project uses pimple which means I'll probably have to play with the library separately.
 
4:20 PM
Does anyone know off the top of their head if PHP will optimize chained concats to preallocate memory for the end result?
assuming one or more dynamic variables
 
4:48 PM
there is optimization for constant literal concatenations, they're performed early (during compile) ...
we can't optimize around unknown values though, we can't tell how much memory to allocate given "forty" . $two where $two is not a known value
 
5:00 PM
@JoeWatkins Say I'm concatenating only a few bytes to the front of a long string (maybe 20k or more) and writing it to a socket. Any inclination if it be better to concat the string and do one write, or do two writes?
 
do two writes
 
we're trying to attack some performance issues from two angles, the amp framing and send performance, and the json encoding performance. Particually when the same data is encoded tens of thousands of times as part of a nested structure
 
okay, what you got so far ?
 
From the JSON side we wrote an extension that provides an interface with a toSerializedJson method on it, when the internal json encoder encounters it, it copies the data straight from a pre-computed zend_string rather than regenerating it each time, that yielded about 400% vs repeated encoding
 
is it context aware ? what I mean by that is
    $string = json_encode($values);

    $string = json_encode($values);
god I hate markdown ...
 
5:12 PM
I'm not sure what you mean
 
what happens the second call when it encounters values encoded for the first call ?
I'm really asking what happens if I change $values between those calls ...
 
it will hit the custom path in encode zval and hit up a mechanism to get the cached copy, then appends it straight onto the smart string buffer
ah, the data is immutable.
 
just so we're clear, if $values is instanceof YourJSONInterface and I change the shape of $values between calls, the implementation will use the cached string from the first call ? isn't that going to be confusing to use ?
 
the cached string is cached within $values itself.
 
$values = new DTO()
$values->andSoOn = "string";

json_encode($values);

/* std object for values has cached string */

$values->furtherMore = "stuff";

json_encode($values); /* this gets the cached string and is missing furtherMore ? */
 
5:17 PM
values is an immutable object, all its properties are readonly
 
this is imposed by the interface ?
 
Technically it's imposed by a function on the interface, the handler calls toSerializedJson(): string and that has a return $this->_cache ??= json_encode($this->readonlyPropertyData);
Technically it could have the object changed however it wished as long as toSerializedJson detected the change and presented the right data next call
 
this might be a place for internals magic
 
So while i'm working on that, trowski is trying to micro-optimize amp's framing and sending.... we're pushing this hard, encoding and streaming many hundreds of MB/sec of data
@JoeWatkins Anything in particular you have in mind you might be willing to share?
 
6:02 PM
krakjoe@Fiji:/opt/src/php-src$ cat test.php
<?php
class Foo implements JsonSerializable {
	public $bar;

	public function jsonSerialize() {

		return $this;
	}
}

$bench = function($foo, $options = 0) {
	$start = microtime(true);
	for ($i = 0; $i < 10000; $i++) {
		$retval = json_encode([
			"one" => $foo,
			"two" => $foo,
			"three" => $foo,
			"four" => $foo,
			"five" => $foo
		], $options);
	}

	printf("Total: %.3f seconds\n", microtime(true)-$start);

	return $retval;
};

$foo = new Foo;
$foo->bar = "hello";
 
You modded the json_encoder directly with an additional flag?
 
yes
 
@JoeWatkins Now set Foo::$bar to be a string, say maybe 200 chars.
 
krakjoe@Fiji:/opt/src/php-src$ sapi/cli/php -n test.php
Total: 0.022 seconds
---------------------------------
Total: 0.010 seconds
---------------------------------
krakjoe@Fiji:/opt/src/php-src$
 
how are you applying the caching?
 
6:09 PM
I think it makes sense ... you may also cache arrays
 
Ah using a hash lookup, i'm not certain how well that would scale in our case, these are long running processes with hundreds of thousands of large arrays, most of which are only partially cached.
 
it works for the duration of encode() if there are no side effects in jsonSerialize ...
(and would work for arrays too, there are no side effects while encoding arrays)
 
Hm, interesting, although I'm not sure. I'd be happy to set up a call and show you what we're working on at some point if it's something you'd be interested in.
 
For our use, the caching needs to happen across multiple calls to json_encode.
It would be really great if php_json_encode_zval was exported :P
 
Well we'd need to override it.
 
6:21 PM
morning
 
o/
 
How is it going Mark
 
Cold and snowy. Quite annoying really. Yourself Sal?
 
You got snow? I just got cold. It was a gorgeous day, even though it started with me having to escape from Gatwick airport.
 
What part are you at? Doing well just had breakfast. It's getting cold here in SoCal.
 
6:23 PM
Yup it's about 2c here in Sheffield, a couple of inches of settled snow on the ground
 
it's less here, I think it's -2°C right now
 
twitter.com/shefffoodlover/status/1464613787055665160/photo/1 this was cool, didn't see it myself though
 
@Trowski if you're tied to doing it in an extension, you can just implement your own encoder (and API) ... the difficult bit in json is the parser, the encode() bit is relatively simple to just do yourself ...
 
@MarkR I walked 33 km :-)
 
@JoeWatkins I copied and pasted the json_encoder.c :P
 
6:26 PM
@MarkR Ah, true, since an array might contain objects with a cached value. Would be nice then if the other encode functions were exported.
 
it just needed a lot of code copying because almost nothing from the original encoder is exported
 
@JoeWatkins Right, would be nice if we didn't have to copy/pasta the string encoder, etc. but it's not a lot of code and unlikely to change.
 
@Trowski Can you paste the code from the extension's C file a gist please? I'm not at my desk.
 
Ta. Relevant lines are 706 and 618
 
6:38 PM
if ultimate speed is the goal, then I have another idea
it's horrible
is ultimate speed the actual goal ?
 
Pretty much. There's a metric ton of logic creating the data, but that all is super speedy.
 
what if you change your interface to return a reference ?
you can avoid the call by detecting changes in the variable the reference points too
 
Trowski has a prototype where the return value of the first call is being written back to a property and re-used after that, but that incurs some other design considerations
 
the problem you have to solve, or the main problem I see with what you're trying to do, is that a global cache that is extremely expensive to access (because it requires a call into userland), might not be very effective as a caching mechanism ...
 
it yielded a 400% performance improvement vs re-encoding the entire structure again in real world data
 
6:46 PM
That's why I was prototyping a version that held the value in a property to avoid the userland call.
I hit an internals knowledge wall though, as I apparently did something wrong with my class definition so it was blowing up when I tried to extend it with a class using readonly properties.
Though yes, even with the userland call, the performance benefits are quite amazing.
 
We also tried pre-allocating a larger buffer for the smart string, but it didn't seem to have much effect at all
 
the heap is preallocated
@Trowski I tried to use them once from an extension, like last week, and it blew up so I bravely gave up ... I didn't look at why yet ...
 
With the 4k pages of the smart string it was reallocating the string around 500 times in certain situations.
 
@JoeWatkins Can you point to what I have to do on a internal class definition so it's safe to extend in userland?
 
urm, nothing special
 
6:54 PM
The error made it sound like the readonly property was being written outside the constructor, even though it was actually a promoted property.
So I assumed I was initializing the internal class object in some wrong way.
The internal class was abstract with no constructor, in case that's relevant.
 
do a zend_test patch so I can look ?
 
3v4l.org/UhirM not just internally
 
The property wasn't declared in the parent.
 
@MarkR that's by design
> This variant is not allowed, as the initializing assignment occurs from outside the class:
also ... it's not really true that the heap is pre-allocated ... normally you can assume it is, the mm maps chunks as it needs them and most of the time emalloc won't result in more chunks, especially as they are never released and we're talking about long running application ... but I guess you could see the result of that in the bench for this kind of thing ...
 
7:15 PM
@JoeWatkins Working on it.
 
 
1 hour later…
8:26 PM
@JoeWatkins So I wasn't able to reproduce it in zend_test :P
 
9:11 PM
hard exit (255) on var_dump of fclose(STDOUT) result: 3v4l.org/RLCh9 - why is it puzzling me that much? is this an error reporting issue? (var_export also exits).
 
cmb
9:34 PM
not sure what's exactly happening, but you can't write to a closed stream
 
 
1 hour later…
10:55 PM
@hakre feels like a straight bug since STDERR works fine 3v4l.org/gnWPD
I'm not sure it makes sense to close a console handle from a running process and thus it's probably "undefined behaviour" but still I would expect both to behave in the same undefined way
 
cmb
The point is that the var_dump() output is supposed to be send to STDOUT, but that has been closed already. 3v4l.org/VmmRN is similar (though the issue is explicitly caught).
 
@cmb that I didn't thought about and makes sense as var_dump() writes to STDOUT which then already is closed. Thanks for hint, didn't think about the obvious.
 
@cmb ohhh right yeh
 
However, what about not seeing a diagnostic message on the SAPI error channel?
Is it because it's stream related and I need to activate error logging to file explicitly?
 
yeh, this works 3v4l.org/VZMsX
 
11:00 PM
Running a test in CLI ...
 
@hakre no it's just generally that var_dump() writes to the output buffer which is automatically flushed to stdio handle #1
and you closed the last ref to that fd
 
so this is on the system level and the kernel kills the process?
normally when I see 255 I think its a fatal error in PHP.
 
possibly, I would guess it varies system to system, the buffer is being implicitly flushed during shutdown
you might get an explicit error from ob_flush()?
oh no
woah wait wtf that mitigates the crash
 
close(1) = 0
write(1, "Command line code:1:\nbool(true)\n", 32) = -1 EBADF (Bad file descriptor)
 
oh btw 2 questions I just remembered been wanting to ask for a while...
 
11:06 PM
strace php -derror_log=test.log -dlog_errors=1 -r 'var_dump(fclose(STDOUT));'; echo $?
 
1) @IluTov is it a conscious decision not to have ReflectionClass::isEnum() ?
 
@DaveRandom is a class with no cases not an Enum?
(sorry for the distraction)
 
no, enums have magical properties indicated by a flag on the ce
2) does anyone have a good reason not to add the 2nd param for ReflectionClass::__construct(object|string $class, bool $autoload = true)? (which does not currently work like this, for no reason I can see)
 
@DaveRandom @ocramius or @asgrim might have opinions on that.
 
yeh I tend to use reflector libs anyway, but I was messing about with enums the other day and cannot come up with any sane reason not to have them work the same way as *_exists() (which all have that option 2nd arg)
also btw that would be a not-horrific way to implement the theorised symbol_exists() (or whatever you wanna call it) general function which just checks if a name exists in the class_entry table without autoloading
internally it's literally just a case of changing zend_lookup_class() to zend_lookup_class_ex(), I checked
@hakre right, so it seems like the implicit output buffer flush which happens during shutdown doesn't check whether the target fd is valid before attempting to write to it... which is kind of fair enough I guess
as long as you explicitly try to write to it after the fclose() you will get an error, from my experiments
and during shutdown it's reasonable to assume that if you fail to write to one stdio handle you will fail to write to everything
I think the main takeaway for me is: just don't do that :-P
 
11:21 PM
@DaveRandom don't we have instanceof ReflectionEnum instead?
 
not if you do new ReflectionClass($arbitrarySymbol)
which tbf, as a user of reflection, is the most likely scenario
I am given a name and I want to figure out what it represents
class/interface/trait/enum/undefined
where "undefined" might mean "not loaded yet" or "doesn't exist at all" depending on use case
 
Also, isEnum exists
it's just not documented
 
oh lol sorry I saw all the enum reflection stuff doc'd and foolishly assumed that meant it was complete :-P
 
:-)
 
ok cool I will just PR docs instead of src, much easier :-P
 
11:26 PM
haha
 
@DaveRandom yes, good thinking, it's more I stumbled into it, was not really thinking about flcose(STDOUT), and then perhaps more puzzled then anything else. And actually me is still thinking about an error message (also no logs) due to the exit code. The SAPI logger should be stable enough to handle this.
 
agreed it should be possible to produce an error, but it may require re-ordering shutdown routines to do so safely, my gut is that it may be ambiguous at that stage whether anything is still writable. I think it's generally reasonable that if you fail to output an error message, you don't then try to output an error message about that failure
 
00:00 - 15:0015:00 - 00:00

« first day (4061 days earlier)      last day (878 days later) »