Skip to content

Conversation

nielsdos
Copy link
Owner

@nielsdos nielsdos commented Apr 7, 2025

No description provided.

return true;
}
}
};
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: remove this accident

@arnaud-lb
Copy link

Thank you for trying this!

I get -0.14% wall time on symfony demo:

base:        mean:  1.0295;  stddev:  0.0012;  diff:  -0.00%
cache-slot:  mean:  1.0281;  stddev:  0.0012;  diff:  -0.14%

(Average of 5 runs -T10,100 runs)

We may avoid allocating a cache slot for simple types, as we use it only for complex ones.

@nielsdos
Copy link
Owner Author

nielsdos commented Apr 9, 2025

We may avoid allocating a cache slot for simple types, as we use it only for complex ones.

Good point.

I get -0.14% wall time on symfony demo:

For me it's a bit of a hit or miss on my older CPU. I can try again on some more recent machine a bit later.

I also see only now that Ilija also tried something like this (before I removed the original cache slot implementation): iluuu1994#155
Maybe I can also check it earlier, however I don't want to cache it later as that can slow down the path that doesn't use objects.

@nielsdos
Copy link
Owner Author

I just committed this to run in CI and get a CI Valgrind bench going:

diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index 7d2e4112797..563e12d3af2 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -1145,9 +1145,9 @@ static zend_always_inline bool zend_check_type_slow(
 		bool is_return_type, bool is_internal)
 {
 	if (ZEND_TYPE_IS_COMPLEX(*type) && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
-		if (*cache_slot == Z_OBJCE_P(arg)) {
-			return true;
-		}
+		// if (*cache_slot == Z_OBJCE_P(arg)) {
+			// return true;
+		// }
 		zend_class_entry *ce;
 		if (UNEXPECTED(ZEND_TYPE_HAS_LIST(*type))) {
 			if (ZEND_TYPE_IS_INTERSECTION(*type)) {
@@ -1242,6 +1242,10 @@ static zend_always_inline bool zend_verify_recv_arg_type(const zend_function *zf
 	ZEND_ASSERT(arg_num <= zf->common.num_args);
 	cur_arg_info = &zf->common.arg_info[arg_num-1];
 
+	if (Z_TYPE_P(arg) == IS_OBJECT && *cache_slot == Z_OBJCE_P(arg)) {
+		return 1;
+	}
+
 	if (ZEND_TYPE_IS_SET(cur_arg_info->type)
 			&& UNEXPECTED(!zend_check_type(&cur_arg_info->type, arg, cache_slot, zf->common.scope, 0, 0))) {
 		zend_verify_arg_error(zf, cur_arg_info, arg_num, arg);

I'm afraid this may degrade scalar checks though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants