Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit aed43d2

Browse files
authored
Merge pull request #75 from pinepain/api-improvements
Api improvements and bug fixes
2 parents ec8260b + 2090716 commit aed43d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1260
-128
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ tests/*
33
!tests/.testsuite.php
44
!tests/.v8-helpers.php
55
!tests/.tracking_dtors.php
6+
!tests/stubs
67

78
.deps
89
*.lo

config.m4

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if test "$PHP_V8" != "no"; then
1919
SEARCH_PATH="/usr/local /usr"
2020
SEARCH_FOR="include/v8.h"
2121

22-
V8_MIN_API_VERSION_STR=6.3.163
22+
V8_MIN_API_VERSION_STR=6.3.248
2323

2424
DESIRED_V8_VERSION=`echo "${V8_MIN_API_VERSION_STR}" | $AWK 'BEGIN { FS = "."; } { printf "%s.%s", [$]1, [$]2;}'`
2525

@@ -211,6 +211,7 @@ if test "$PHP_V8" != "no"; then
211211
src/php_v8_symbol_object.cc \
212212
src/php_v8_template.cc \
213213
src/php_v8_return_value.cc \
214+
src/php_v8_callback_info_interface.cc \
214215
src/php_v8_function_callback_info.cc \
215216
src/php_v8_property_callback_info.cc \
216217
src/php_v8_named_property_handler_configuration.cc \

perf/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
composer.lock

perf/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
To run specific perf test execute run something like:
2+
3+
`./vendor/bin/phpbench run <perf test name> --report=aggregate --retry-threshold=5`
4+
5+
For more details see [phpbench documentation](http://phpbench.readthedocs.io/en/latest/introduction.html).
6+
7+
e.g.
8+
9+
- `./vendor/bin/phpbench run src/SetObjectProperty.php --report=aggregate --retry-threshold=5`
10+
11+
- `./vendor/bin/phpbench run src/CreatePrimitiveValue.php --report=aggregate --retry-threshold=5`

perf/composer.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "pinepain/php-v8-perf",
3+
"type": "library",
4+
"description": "Performance tests for pinepain/php-v8 php extension",
5+
"keywords": ["dev", "performance", "benchmark", "tests", "php-v8", "v8", "js", "javascript"],
6+
"homepage": "https://github.com/pinepain/php-v8-perf",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Bogdan Padalko",
11+
"email": "[email protected]",
12+
"homepage": "https://github.com/pinepain"
13+
}
14+
],
15+
"require": {
16+
"php": "~7.1",
17+
"phpbench/phpbench": "^0.13.0"
18+
},
19+
"autoload": {
20+
"psr-4": {
21+
"Pinepain\\V8\\Tests\\Perf\\": "src/"
22+
}
23+
}
24+
}

perf/phpbench.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"bootstrap": "vendor/autoload.php",
3+
"path": "src"
4+
}

perf/src/CreatePrimitiveValue.php

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* This file is part of the pinepain/php-v8 PHP extension.
5+
*
6+
* Copyright (c) 2015-2017 Bogdan Padalko <[email protected]>
7+
*
8+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
9+
*
10+
* For the full copyright and license information, please view the
11+
* LICENSE file that was distributed with this source or visit
12+
* http://opensource.org/licenses/MIT
13+
*/
14+
15+
16+
namespace Pinepain\V8\Tests\Perf;
17+
18+
19+
use V8\BooleanValue;
20+
use V8\Context;
21+
use V8\FunctionObject;
22+
use V8\Isolate;
23+
use V8\NullValue;
24+
use V8\NumberValue;
25+
use V8\ObjectValue;
26+
use V8\StringValue;
27+
use V8\UndefinedValue;
28+
29+
30+
/**
31+
* @Warmup(2)
32+
* @Revs(100)
33+
* @Iterations(10)
34+
* @BeforeMethods("init")
35+
*/
36+
class CreatePrimitiveValue
37+
{
38+
/**
39+
* @var Isolate
40+
*/
41+
private $isolate;
42+
/**
43+
* @var Context
44+
*/
45+
private $context;
46+
/**
47+
* @var FunctionObject
48+
*/
49+
private $fnc;
50+
51+
/**
52+
* @var Context
53+
*/
54+
private $context2;
55+
/**
56+
* @var FunctionObject
57+
*/
58+
private $fnc2;
59+
60+
/**
61+
* @var callable
62+
*/
63+
private $callback;
64+
65+
private $pairs = [];
66+
67+
public function init()
68+
{
69+
$this->isolate = $isolate = new Isolate();
70+
$this->context = $context = new Context($isolate);
71+
72+
$this->fnc = new FunctionObject($context, function () {
73+
if ($this->callback) {
74+
($this->callback)();
75+
}
76+
});
77+
78+
$this->context2 = $context2 = new Context($isolate);
79+
80+
$this->fnc2 = new FunctionObject($context2, function () {
81+
if ($this->callback) {
82+
($this->callback)();
83+
}
84+
});
85+
}
86+
87+
public function benchOutsideContext()
88+
{
89+
$callback = $this->buildCallback();
90+
91+
$callback();
92+
$this->fnc->call($this->context, $this->fnc);
93+
}
94+
95+
public function benchOutsideContextWithWarm()
96+
{
97+
$callback = $this->buildCallback();
98+
99+
$this->fnc->call($this->context, $this->fnc);
100+
$callback();
101+
}
102+
103+
public function benchWithinContext()
104+
{
105+
$this->callback = $this->buildCallback();
106+
$this->fnc->call($this->context, $this->fnc);
107+
}
108+
109+
public function benchWithinContext2()
110+
{
111+
$this->callback = $this->buildCallback();
112+
$this->fnc2->call($this->context2, $this->fnc2);
113+
}
114+
115+
public function benchWithinIsolate()
116+
{
117+
$cb = $this->buildCallback();
118+
$this->fnc->call($this->context, $this->fnc);
119+
120+
$this->isolate->within($cb);
121+
}
122+
123+
public function benchWithinIsolateLight()
124+
{
125+
$cb = $this->buildCallback();
126+
127+
$this->isolate->within($cb);
128+
}
129+
130+
public function benchWithinContextNew()
131+
{
132+
$cb = $this->buildCallback();
133+
$this->fnc->call($this->context, $this->fnc);
134+
135+
$this->context->within($cb);
136+
}
137+
138+
public function benchWithinContextNewLight()
139+
{
140+
$cb = $this->buildCallback();
141+
142+
$this->context->within($cb);
143+
}
144+
145+
protected function buildCallback()
146+
{
147+
$callback = function ($isolate = null) {
148+
$isolate = $isolate ?: $this->isolate;
149+
150+
$values =[];
151+
for ($i = 0; $i < 200; $i++) {
152+
$values[] = new UndefinedValue($isolate);
153+
$values[] = new NullValue($isolate);
154+
$values[] = new BooleanValue($isolate, true);
155+
$values[] = new NumberValue($isolate, 123.456);
156+
$values[] = new StringValue($isolate, 'foo');
157+
}
158+
};
159+
160+
return $callback;
161+
}
162+
}

perf/src/GetObjectProperty.php

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* This file is part of the pinepain/php-v8 PHP extension.
5+
*
6+
* Copyright (c) 2015-2017 Bogdan Padalko <[email protected]>
7+
*
8+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
9+
*
10+
* For the full copyright and license information, please view the
11+
* LICENSE file that was distributed with this source or visit
12+
* http://opensource.org/licenses/MIT
13+
*/
14+
15+
16+
namespace Pinepain\V8\Tests\Perf;
17+
18+
19+
use V8\Context;
20+
use V8\FunctionObject;
21+
use V8\Isolate;
22+
use V8\ObjectValue;
23+
use V8\StringValue;
24+
25+
26+
/**
27+
* @Warmup(2)
28+
* @Revs(100)
29+
* @Iterations(10)
30+
* @BeforeMethods("init")
31+
*/
32+
class GetObjectProperty
33+
{
34+
/**
35+
* @var Isolate
36+
*/
37+
private $isolate;
38+
/**
39+
* @var Context
40+
*/
41+
private $context;
42+
/**
43+
* @var FunctionObject
44+
*/
45+
private $fnc;
46+
/**
47+
* @var ObjectValue
48+
*/
49+
private $obj;
50+
51+
/**
52+
* @var Context
53+
*/
54+
private $context2;
55+
/**
56+
* @var FunctionObject
57+
*/
58+
private $fnc2;
59+
60+
/**
61+
* @var callable
62+
*/
63+
private $callback;
64+
65+
private $keys = [];
66+
67+
public function init()
68+
{
69+
$this->isolate = $isolate = new Isolate();
70+
$this->context = $context = new Context($isolate);
71+
72+
$this->obj = $obj = new ObjectValue($context);
73+
74+
75+
for ($i = 0; $i < 1000; $i++) {
76+
$this->keys[] = $key = new StringValue($isolate, "key_{$i}");
77+
$obj->set($context, $key, $value = new StringValue($isolate, "value_{$i}"));
78+
}
79+
80+
$this->fnc = new FunctionObject($context, function () {
81+
if ($this->callback) {
82+
($this->callback)();
83+
}
84+
});
85+
86+
$this->context2 = $context2 = new Context($isolate);
87+
88+
$this->fnc2 = new FunctionObject($context2, function () {
89+
if ($this->callback) {
90+
($this->callback)();
91+
}
92+
});
93+
}
94+
95+
public function benchOutsideContext()
96+
{
97+
$callback = $this->buildCallback();
98+
99+
$callback();
100+
$this->fnc->call($this->context, $this->fnc);
101+
}
102+
103+
public function benchOutsideContextWithWarm()
104+
{
105+
$callback = $this->buildCallback();
106+
107+
$this->fnc->call($this->context, $this->fnc);
108+
$callback();
109+
}
110+
111+
public function benchWithinContext()
112+
{
113+
$this->callback = $this->buildCallback();
114+
$this->fnc->call($this->context, $this->fnc);
115+
}
116+
117+
public function benchWithinContext2()
118+
{
119+
$this->callback = $this->buildCallback();
120+
$this->fnc2->call($this->context2, $this->fnc2);
121+
}
122+
123+
124+
protected function buildCallback()
125+
{
126+
$callback = function () {
127+
$context = $this->context;
128+
129+
foreach ($this->keys as $key) {
130+
$this->obj->get($context, $key);
131+
}
132+
};
133+
134+
return $callback;
135+
}
136+
}

0 commit comments

Comments
 (0)