Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107939 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 24926 invoked from network); 21 Dec 2019 00:07:58 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 21 Dec 2019 00:07:58 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 8611E2C05A9 for ; Fri, 20 Dec 2019 14:08:43 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 64.147.123.0/24 X-Spam-Virus: No Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Fri, 20 Dec 2019 14:08:42 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id BF2D3509 for ; Fri, 20 Dec 2019 17:08:41 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Fri, 20 Dec 2019 17:08:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=Oxz3F5na6M3K7S0Gcwf5F6cjkpb13 BHbfObgZkZP81I=; b=VNYrkrkxNXmqilaRLfUtcGbjyVqUKMvFIlCLvXSrYeyv5 4wNO+WLWRUYwmS4cmC3iLMX8TVnSVeFT8PGZkUoUxXQFztax6rrMIzkx0lEsiR6r 6jUHyB3kToykJuUNdWa3CaUZMXWGbGkap92nykGUmRXYXABQzGwZm9ycf9Vw8sm7 pqlUuCov8KXkEHP/78ZbtVKKTAUYDlinQFHC9yijK6bUmjegYUMvpdJXM6IxeMZ/ Pj7uAP1TMIRoFzmaG5NEb7rrKQ310xUiyjuyEuB1NB3GABen5+TAZWG3V7s7wEGA Dz0FYEivVDtvJeS7hdYpyKui7Q+jRgEcZjwhld6fg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvddufedgudehhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuffhomhgrihhnpehphhhprdhnvghtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehl rghrrhihsehgrghrfhhivghlughtvggthhdrtghomhenucevlhhushhtvghrufhiiigvpe dt X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id C031114200A1; Fri, 20 Dec 2019 17:08:40 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-694-gd5bab98-fmstable-20191218v1 Mime-Version: 1.0 Message-ID: <2c1288a6-11f3-4c1b-8787-384d33c5b236@www.fastmail.com> Date: Fri, 20 Dec 2019 16:08:19 -0600 To: "php internals" Content-Type: text/plain X-Envelope-From: Subject: FFI, Preload, and performance From: larry@garfieldtech.com ("Larry Garfield") The documentation doesn't really cover this, so I'm hoping it's OK to ask here. The FFI docs say that for web requests, you really really ought to use preloading and then load/scope to manage an FFI library because it's going to be too slow to link up otherwise. See the example here: https://www.php.net/manual/en/ffi.examples-complete.php What is unclear, though, is the performance impact of calling scope(). It happens at runtime in the example so I presume it's "fast enough" at runtime. However, is it expected that it's only ever called once for a given scope? Or would it be safe to call multiple times in different places just to get an unshared reference to it? Basically, would this be safe or a bad idea, and why? final class PrintProxy { private static $ffi = null; function __construct() { if (is_null(self::$ffi)) { self::$ffi = FFI::scope("DUMMY"); } } function printf($format, ...$args) { return (int)self::$ffi->printf($format, ...$args); } } final class SprintfProxy { private static $ffi = null; function __construct() { if (is_null(self::$ffi)) { self::$ffi = FFI::scope("DUMMY"); } } function printf($format, ...$args) { return (string)self::$ffi->sprintf($format, ...$args); } } The alternative being to have a single object that wraps scope("DUMMY") just once, and then inject that into both of those classes. Is that worth the extra hassle or no, and why? Thanks to anyone who can help clear this up. (Dmitri? Zeev?) -- Larry Garfield larry@garfieldtech.com