Skip to content

Conversation

@devnexen
Copy link
Member

@devnexen devnexen commented Nov 23, 2025

Replace separate num_errors/errors fields with a single struct containing size, capacity, and a flexible array. The buffer grows by 50% when needed instead of reallocating on every recorded error.

  • Add ZEND_ERR_BUF_SIZE macro and zend_init_errors_buf() helper
  • Allocate error buffer in zend_startup for NTS builds
  • Remove redundant NULL checks since buffer is always allocated

@ndossche
Copy link
Member

It's often a good idea to choose a factor of 1.5, there's a mathematical reason behind it (https://github.com/facebook/folly/blob/main/folly/docs/FBVector.md#memory-handling).

@devnexen
Copy link
Member Author

yes will try ; even though usage and growth might not be that as critical as your (nice) link contexts.

@Girgias
Copy link
Member

Girgias commented Nov 23, 2025

It's often a good idea to choose a factor of 1.5, there's a mathematical reason behind it (https://github.com/facebook/folly/blob/main/folly/docs/FBVector.md#memory-handling).

Interesting, we currently extend arrays by a factor of 2, I wonder what would happen if we do 1.5 instead.

@ndossche
Copy link
Member

Interesting, we currently extend arrays by a factor of 2, I wonder what would happen if we do 1.5 instead.

Won't work because the hash masking depends on it being a power of 2.

@devnexen devnexen marked this pull request as ready for review November 23, 2025 13:55
@devnexen devnexen requested a review from dstogov as a code owner November 23, 2025 13:55
@TimWolla
Copy link
Member

Can we get a clearer PR title?

@devnexen devnexen changed the title Zend little upd Zend internal changes: error handling and zend_make_compiled_string_description() takes in account lineno is uint32_t Nov 24, 2025
@devnexen devnexen requested a review from ndossche December 5, 2025 23:35
Zend/zend.c Outdated
* Use pow2 realloc if it becomes a problem. */
EG(num_errors)++;
EG(errors) = erealloc(EG(errors), sizeof(zend_error_info*) * EG(num_errors));
// pondering if uint32_t is more appropriate but would need to align the allocation size then
Copy link
Member

Choose a reason for hiding this comment

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

Storing the size like this is very ugly in my opinion. What you could do is make a struct with a size field and a flexible array member at the end.

@devnexen devnexen marked this pull request as draft January 4, 2026 20:09
@devnexen devnexen force-pushed the zend_little_upd branch 8 times, most recently from f38b0e3 to 078130f Compare January 5, 2026 07:15
@devnexen devnexen force-pushed the zend_little_upd branch 6 times, most recently from 4625478 to 21c2fdc Compare January 17, 2026 15:00
Replace separate num_errors/errors fields with a single struct containing
size, capacity, and a flexible array. The buffer grows by 50% when needed
instead of reallocating on every recorded error.

- Add ZEND_ERR_BUF_SIZE macro and zend_init_errors_buf() helper
- Allocate error buffer in zend_startup for NTS builds
- Remove redundant NULL checks since buffer is always allocated
@devnexen devnexen changed the title Zend internal changes: error handling and zend_make_compiled_string_description() takes in account lineno is uint32_t Zend: Preallocate error buffer with capacity tracking 5111ca5 Replace separate num_errors/errors fields with a single struct containing size, capacity, and a flexible array. The buffer grows by 50% when needed instead of reallocating on every recorded error. - Add ZEND_ERR_BUF_SIZE macro and zend_init_errors_buf() helper - Allocate error buffer in zend_startup for NTS builds - Remove redundant NULL checks since buffer is always allocated Jan 17, 2026
@devnexen devnexen changed the title Zend: Preallocate error buffer with capacity tracking 5111ca5 Replace separate num_errors/errors fields with a single struct containing size, capacity, and a flexible array. The buffer grows by 50% when needed instead of reallocating on every recorded error. - Add ZEND_ERR_BUF_SIZE macro and zend_init_errors_buf() helper - Allocate error buffer in zend_startup for NTS builds - Remove redundant NULL checks since buffer is always allocated Zend: Preallocate error buffer with capacity tracking Jan 17, 2026
@devnexen devnexen marked this pull request as ready for review January 17, 2026 15:48
@devnexen devnexen requested a review from ndossche January 17, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants