perf(build): skip opcode work for ordinary PHP sources

master
韩天峰 3 weeks ago
parent 4f8acf0c08
commit f3999413f2
  1. 8
      phpunit/src/EmptyTranslationUnitTest.php
  2. 19
      src/Build/SourcePipelineTrait.php
  3. 5
      src/Translator.php

@ -118,9 +118,13 @@ PHP);
$this->compiler->prepareFile($source);
$sources = $this->compiler->convert([$source]);
self::assertCount(2, $sources);
self::assertCount(1, $sources);
self::assertContains($this->compiler->getBuildDir() . '/extension-app.cc', $sources);
self::assertContains($this->compiler->getBuildDir() . '/embedded-opcodes-app.cc', $sources);
self::assertNotContains($this->compiler->getBuildDir() . '/embedded-opcodes-app.cc', $sources);
self::assertStringContainsString(
'void typephp_opcode_table_install(void) {}',
file_get_contents($this->compiler->getBuildDir() . '/extension-app.cc'),
);
foreach ($sources as $generatedSource) {
self::assertFileExists($generatedSource);
}

@ -1013,12 +1013,16 @@ PHP
&& file_get_contents($anonymousManifest) === '[]') {
unlink($anonymousManifest);
}
$needsAnonymousRefresh = is_file($legacyAnonymousManifest)
|| ($this->canEmbedAnonymousClassOpcode()
&& !is_file($anonymousManifest)
&& preg_match('/new\s+class\b/', (string) file_get_contents($path)) === 1);
if (!$this->shouldRegeneratePhpFile($path) && !$needsAnonymousRefresh) {
if ($this->canEmbedAnonymousClassOpcode()) {
$shouldRegenerate = $this->shouldRegeneratePhpFile($path);
$hasAnonymousManifest = is_file($anonymousManifest);
$needsAnonymousRefresh = !$shouldRegenerate
&& (is_file($legacyAnonymousManifest)
|| ($hasAnonymousManifest
? !$this->canEmbedAnonymousClassOpcode()
: (preg_match('/new\s+class\b/', (string) file_get_contents($path)) === 1
&& $this->canEmbedAnonymousClassOpcode())));
if (!$shouldRegenerate && !$needsAnonymousRefresh) {
if ($hasAnonymousManifest) {
$this->restoreAnonymousManifest($path);
}
$validSourceCount++;
@ -1114,7 +1118,8 @@ PHP
// Nano keeps the ordinary statically registered Zend class/module
// metadata, then adds a direct native process entry beside it.
$sourceFiles[] = $this->genExtension();
if ($this->isBuildModeEmbed() && !$this->isNanoMode()) {
if ($this->isBuildModeEmbed() && !$this->isNanoMode()
&& ($this->bundledFiles !== [] || $this->embeddedOpcodeFiles !== [])) {
array_push($sourceFiles, ...$this->genEmbeddedOpcodeTable());
}
if ($this->isNanoMode()) {

@ -1234,6 +1234,11 @@ class Translator extends Preprocessor
if ($this->isBuildModeEmbed() && !$this->isNanoMode()) {
$code .= '#include <typephp_runtime.h>' . PHP_EOL;
if ($this->bundledFiles === [] && $this->embeddedOpcodeFiles === []) {
// The runtime still calls these hooks; keep empty builds in this translation unit.
$code .= 'extern "C" void typephp_opcode_table_install(void) {}' . PHP_EOL;
$code .= 'extern "C" void typephp_opcode_table_uninstall(void) {}' . PHP_EOL;
}
}
if ($this->isBuildModeLib() && !$this->isWindows()) {

Loading…
Cancel
Save