Skip to content

configurable apcu compression level#96

Open
pavetheway91 wants to merge 1 commit into
kjdev:masterfrom
pavetheway91:apcu_level
Open

configurable apcu compression level#96
pavetheway91 wants to merge 1 commit into
kjdev:masterfrom
pavetheway91:apcu_level

Conversation

@pavetheway91
Copy link
Copy Markdown

@pavetheway91 pavetheway91 commented May 28, 2026

New ini setting "zstd.apcu_compression_level"

Summary by CodeRabbit

  • New Features
    • New INI setting zstd.apcu_compression_level (when APCu support is enabled) to control APCu zstd compression level at runtime. Invalid or zero values fall back to the safe default.
  • Tests
    • APCu serializer tests updated to compare stored entry sizes across compression levels and assert when higher compression yields smaller entries.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Warning

Review limit reached

@pavetheway91, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 17 minutes and 27 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 66a9a72c-725b-4919-850e-2421371f8975

📥 Commits

Reviewing files that changed from the base of the PR and between 6e79e81 and 1a3212a.

📒 Files selected for processing (3)
  • php_zstd.h
  • tests/apcu_serializer.phpt
  • zstd.c
📝 Walkthrough

Walkthrough

Adds an APCu-facing module global and INI for zstd compression level; APCu serializer reads and validates the setting (falls back on default) and uses it for compression; tests compare APCu stored sizes at different levels.

Changes

APCu Compression Level Configuration

Layer / File(s) Summary
Module global field declaration and guard adjustment
php_zstd.h
Unconditionally declares ZEND_BEGIN_MODULE_GLOBALS(zstd) and adds zend_long apcu_compression_level under #if defined(HAVE_APCU_SUPPORT); adjusts surrounding preprocessor guard placement.
APCu serializer reads and validates level
zstd.c
Reads PHP_ZSTD_G(apcu_compression_level), validates via zstd_check_compress_level (treating 0 as invalid), falls back to ZSTD_CLEVEL_DEFAULT if invalid, and uses the chosen level in ZSTD_compress.
INI registration and lifecycle wiring
zstd.c
Adds zstd.apcu_compression_level INI entry (guarded by HAVE_APCU_SUPPORT) wired to the module global; adjusts REGISTER/UNREGISTER/DISPLAY INI calls to run without the previous PHP_VERSION_ID >= 80000 guard where applicable.
APCu serializer test for large payloads
tests/apcu_serializer.phpt
Adds getEntrySize() helper, stores a payload at compression levels 3 and 19, compares APCu mem_size for the key, and prints SMALLER when level 19 yields a smaller stored entry; expected output updated.

Sequence Diagram(s)

sequenceDiagram
  participant Test as tests/apcu_serializer.phpt
  participant APCuSerializer as APCu_zstd_serializer
  participant ModuleGlobals as PHP_ZSTD_G(apcu_compression_level)
  participant ZSTD as ZSTD_compress

  Test->>APCuSerializer: apcu_store(big_payload)
  APCuSerializer->>ModuleGlobals: read apcu_compression_level
  APCuSerializer->>APCuSerializer: validate level (zstd_check_compress_level), fallback if invalid/0
  APCuSerializer->>ZSTD: ZSTD_compress(data, chosen_level)
  ZSTD-->>APCuSerializer: compressed_data
  APCuSerializer-->>Test: store result and update apcu_cache_info
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hop through bytes and tweak the tune,
INI whispers levels under the moon,
I stash the payload, measure with care,
From three to nineteen — which one is spare?
"SMALLER!" I cheer, a compressed affair.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'configurable apcu compression level' directly and accurately describes the main change: adding a configurable INI setting for APCu compression level across all three modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kjdev
Copy link
Copy Markdown
Owner

kjdev commented May 29, 2026

I think the implementation is good, but I'd also like to see some test code. 

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/apcu_serializer.phpt`:
- Around line 72-79: The test reads mem_size from
apcu_cache_info()['cache_list'][0] and asserts $b < $a which is flaky; instead,
find the mem_size entry for the stored key "big_entry" from apcu_cache_info()
(search cache_list entries for ['info'] or ['key'] == 'big_entry') and compare
that mem_size before and after setting ini_set('zstd.apcu_compression_level',
19) so you measure the specific item's size, and change the assertion to allow
equality (use $b <= $a) to avoid nondeterministic failures; apply the same fix
to the second occurrence around the later assertion.
- Around line 67-68: Replace the raw file_get_contents(...) expression with a
guarded read: call file_get_contents(...) into a variable (e.g. $payload or
$zstd_source), check if the result === false, and if so print an explicit
failure message to STDERR and exit with non‑zero status (e.g. fwrite(STDERR,
"Failed to read fixture: ...\n"); exit(1);); then use that variable where the
original file_get_contents(...) result was used in the test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d988a944-b5df-4c11-84c7-9d38c5431e55

📥 Commits

Reviewing files that changed from the base of the PR and between bfe2a02 and d2741d8.

📒 Files selected for processing (3)
  • php_zstd.h
  • tests/apcu_serializer.phpt
  • zstd.c
✅ Files skipped from review due to trivial changes (1)
  • php_zstd.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • zstd.c

Comment thread tests/apcu_serializer.phpt Outdated
Comment on lines +67 to +68
file_get_contents(__DIR__ . '/../zstd.c')
];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fail fast if payload fixture read fails.

If file_get_contents() returns false, this test may pass/fail for the wrong reason. Add a guard and explicit failure output/exit.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/apcu_serializer.phpt` around lines 67 - 68, Replace the raw
file_get_contents(...) expression with a guarded read: call
file_get_contents(...) into a variable (e.g. $payload or $zstd_source), check if
the result === false, and if so print an explicit failure message to STDERR and
exit with non‑zero status (e.g. fwrite(STDERR, "Failed to read fixture: ...\n");
exit(1);); then use that variable where the original file_get_contents(...)
result was used in the test.

Comment thread tests/apcu_serializer.phpt Outdated
@pavetheway91 pavetheway91 force-pushed the apcu_level branch 2 times, most recently from 5b02610 to 3f1e32d Compare May 29, 2026 04:20
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/apcu_serializer.phpt`:
- Around line 66-71: The test iterates apcu_cache_info()['cache_list'] without
guarding that apcu_cache_info() returned valid metadata, which can raise
warnings and break the test; update the code around the foreach (the call to
apcu_cache_info() and the loop over 'cache_list') to first fetch the result into
a variable, verify it's not false/null and that 'cache_list' exists and is an
array, and if not return null explicitly before attempting to iterate.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 05daba65-f658-41a1-b8af-dd9f5f45e23e

📥 Commits

Reviewing files that changed from the base of the PR and between 5b02610 and 3f1e32d.

📒 Files selected for processing (3)
  • php_zstd.h
  • tests/apcu_serializer.phpt
  • zstd.c
🚧 Files skipped from review as they are similar to previous changes (2)
  • php_zstd.h
  • zstd.c

Comment thread tests/apcu_serializer.phpt Outdated
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

✅ Actions performed

Reviews resumed.

@pavetheway91
Copy link
Copy Markdown
Author

pavetheway91 commented May 30, 2026

fixed php7

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
tests/apcu_serializer.phpt (1)

87-89: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Make the size assertion non-flaky on Line 87.

Using strict $b < $a can fail nondeterministically when both levels produce equal APCu entry size. Use <= to keep the intent while stabilizing CI.

Suggested patch
-if ($a !== null && $b !== null && $b < $a) {
+if ($a !== null && $b !== null && $b <= $a) {
   echo "SMALLER\n";
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/apcu_serializer.phpt` around lines 87 - 89, The size comparison using
strict inequality currently reads as a potential flaky check (the condition
using $b < $a), so update the conditional in the test to use a non-strict
comparison ($b <= $a) when evaluating $a and $b to stabilize the assertion that
the second size is not greater than the first while leaving the echo "SMALLER\n"
behavior intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@php_zstd.h`:
- Around line 47-60: The zend_zstd_globals struct can be empty when
HAVE_APCU_SUPPORT is unset and PHP_VERSION_ID < 80000; ensure the globals struct
always has at least one member by adding a fallback dummy field (e.g., zend_long
dummy or char dummy) inside the ZEND_BEGIN_MODULE_GLOBALS(zstd) block under the
appropriate `#else` branch so zend_zstd_globals is never empty while keeping
ZEND_BEGIN_MODULE_GLOBALS(zstd) and ZEND_DECLARE_MODULE_GLOBALS(zstd) unguarded;
update any conditional compilation around the other members
(output_compression*, ob_handler, handler_registered, compression_coding,
apcu_compression_level) to retain their current guards.

---

Duplicate comments:
In `@tests/apcu_serializer.phpt`:
- Around line 87-89: The size comparison using strict inequality currently reads
as a potential flaky check (the condition using $b < $a), so update the
conditional in the test to use a non-strict comparison ($b <= $a) when
evaluating $a and $b to stabilize the assertion that the second size is not
greater than the first while leaving the echo "SMALLER\n" behavior intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d626bf45-0ef0-44b8-88e6-f063b3ea1ca6

📥 Commits

Reviewing files that changed from the base of the PR and between 3f1e32d and 6e79e81.

📒 Files selected for processing (3)
  • php_zstd.h
  • tests/apcu_serializer.phpt
  • zstd.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • zstd.c

Comment thread php_zstd.h
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