From dce7987d25454d188724079ec5f4694660e3ee5e Mon Sep 17 00:00:00 2001 From: Joseph Bui Date: Thu, 13 Jun 2019 18:00:02 -0700 Subject: [PATCH 01/13] added basic script store --- vnext/ReactUWP/Base/UwpReactInstance.cpp | 7 ++++++- vnext/ReactUWP/ChakraScriptStore.cpp | 23 +++++++++++++++++++++++ vnext/ReactUWP/ChakraScriptStore.h | 13 +++++++++++++ vnext/ReactUWP/ReactUWP.vcxproj | 4 +++- vnext/ReactUWP/ReactUWP.vcxproj.filters | 6 ++++++ vnext/package.json | 2 +- 6 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 vnext/ReactUWP/ChakraScriptStore.cpp create mode 100644 vnext/ReactUWP/ChakraScriptStore.h diff --git a/vnext/ReactUWP/Base/UwpReactInstance.cpp b/vnext/ReactUWP/Base/UwpReactInstance.cpp index c141f793535..c5dbdb6af87 100644 --- a/vnext/ReactUWP/Base/UwpReactInstance.cpp +++ b/vnext/ReactUWP/Base/UwpReactInstance.cpp @@ -63,6 +63,8 @@ #include #include +#include + #if !defined(OSS_RN) #include "ChakraJSIRuntimeHolder.h" #endif @@ -272,7 +274,10 @@ void UwpReactInstance::Start(const std::shared_ptr& spThis, cons #if !defined(OSS_RN) if (settings.UseJsi) - devSettings->jsiRuntimeHolder = std::make_shared(devSettings, jsQueue, nullptr, nullptr); + { + std::unique_ptr scriptStore = std::make_unique(); + devSettings->jsiRuntimeHolder = std::make_shared(devSettings, jsQueue, std::move(scriptStore), nullptr); + } #endif try diff --git a/vnext/ReactUWP/ChakraScriptStore.cpp b/vnext/ReactUWP/ChakraScriptStore.cpp new file mode 100644 index 00000000000..3d72fa42843 --- /dev/null +++ b/vnext/ReactUWP/ChakraScriptStore.cpp @@ -0,0 +1,23 @@ +#include "pch.h" +#include "ChakraScriptStore.h" + +namespace react { + namespace uwp { + + facebook::jsi::VersionedBuffer ChakraScriptStore::getVersionedScript(const std::string& url) noexcept + { + facebook::jsi::VersionedBuffer versionedBuffer_; + versionedBuffer_.buffer = 0; + versionedBuffer_.version = 0; + + return versionedBuffer_; + } + + facebook::jsi::ScriptVersion_t ChakraScriptStore::getScriptVersion(const std::string& url) noexcept + { + facebook::jsi::ScriptVersion_t scriptVersion_ = 0; + + return scriptVersion_; + } + } +} diff --git a/vnext/ReactUWP/ChakraScriptStore.h b/vnext/ReactUWP/ChakraScriptStore.h new file mode 100644 index 00000000000..8a9360fa6b5 --- /dev/null +++ b/vnext/ReactUWP/ChakraScriptStore.h @@ -0,0 +1,13 @@ +#pragma once +#include + +namespace react { + namespace uwp { + class ChakraScriptStore : public facebook::jsi::ScriptStore + { + public: + facebook::jsi::VersionedBuffer getVersionedScript(const std::string& url) noexcept override; + facebook::jsi::ScriptVersion_t getScriptVersion(const std::string& url) noexcept override; + }; + } +} diff --git a/vnext/ReactUWP/ReactUWP.vcxproj b/vnext/ReactUWP/ReactUWP.vcxproj index 04fe9bdf063..5d972e50502 100644 --- a/vnext/ReactUWP/ReactUWP.vcxproj +++ b/vnext/ReactUWP/ReactUWP.vcxproj @@ -161,6 +161,7 @@ + @@ -230,9 +231,10 @@ - + + diff --git a/vnext/ReactUWP/ReactUWP.vcxproj.filters b/vnext/ReactUWP/ReactUWP.vcxproj.filters index a6dda3d53d1..b2038d9995c 100644 --- a/vnext/ReactUWP/ReactUWP.vcxproj.filters +++ b/vnext/ReactUWP/ReactUWP.vcxproj.filters @@ -219,6 +219,9 @@ Views + + Utils + @@ -438,6 +441,9 @@ Views + + Utils + diff --git a/vnext/package.json b/vnext/package.json index 58060629adb..c6307531cf9 100644 --- a/vnext/package.json +++ b/vnext/package.json @@ -72,4 +72,4 @@ "react": "16.8.3", "react-native": "^0.59.0 || 0.59.0-microsoft.1 || https://github.com/Microsoft/react-native/archive/v0.59.0-microsoft.1.tar.gz" } -} \ No newline at end of file +} From c6577a73fea6ef066919a3387cddcf1a1631162a Mon Sep 17 00:00:00 2001 From: Joseph Bui Date: Thu, 13 Jun 2019 18:11:11 -0700 Subject: [PATCH 02/13] add basic prepared script store --- vnext/ReactUWP/Base/UwpReactInstance.cpp | 8 +++++- vnext/ReactUWP/ChakraPreparedScriptStore.cpp | 26 ++++++++++++++++++++ vnext/ReactUWP/ChakraPreparedScriptStore.h | 23 +++++++++++++++++ vnext/ReactUWP/ReactUWP.vcxproj | 2 ++ vnext/ReactUWP/ReactUWP.vcxproj.filters | 6 +++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 vnext/ReactUWP/ChakraPreparedScriptStore.cpp create mode 100644 vnext/ReactUWP/ChakraPreparedScriptStore.h diff --git a/vnext/ReactUWP/Base/UwpReactInstance.cpp b/vnext/ReactUWP/Base/UwpReactInstance.cpp index c5dbdb6af87..4fcd9c43a51 100644 --- a/vnext/ReactUWP/Base/UwpReactInstance.cpp +++ b/vnext/ReactUWP/Base/UwpReactInstance.cpp @@ -64,6 +64,7 @@ #include #include +#include #if !defined(OSS_RN) #include "ChakraJSIRuntimeHolder.h" @@ -276,7 +277,12 @@ void UwpReactInstance::Start(const std::shared_ptr& spThis, cons if (settings.UseJsi) { std::unique_ptr scriptStore = std::make_unique(); - devSettings->jsiRuntimeHolder = std::make_shared(devSettings, jsQueue, std::move(scriptStore), nullptr); + std::unique_ptr preparedScriptStore = std::make_unique(); + devSettings->jsiRuntimeHolder = std::make_shared( + devSettings, + jsQueue, + std::move(scriptStore), + std::move(preparedScriptStore)); } #endif diff --git a/vnext/ReactUWP/ChakraPreparedScriptStore.cpp b/vnext/ReactUWP/ChakraPreparedScriptStore.cpp new file mode 100644 index 00000000000..560310dfad4 --- /dev/null +++ b/vnext/ReactUWP/ChakraPreparedScriptStore.cpp @@ -0,0 +1,26 @@ +#include "pch.h" +#include "ChakraPreparedScriptStore.h" + +namespace react { + namespace uwp { + + std::unique_ptr ChakraPreparedScriptStore::tryGetPreparedScript( + const facebook::jsi::ScriptSignature& scriptSignature, + const facebook::jsi::JSRuntimeSignature& runtimeSignature, + const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. + ) noexcept + { + return nullptr; + } + + void ChakraPreparedScriptStore::persistPreparedScript( + std::shared_ptr preparedScript, + const facebook::jsi::ScriptSignature& scriptMetadata, + const facebook::jsi::JSRuntimeSignature& runtimeMetadata, + const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. + ) noexcept + { + + } + } +} diff --git a/vnext/ReactUWP/ChakraPreparedScriptStore.h b/vnext/ReactUWP/ChakraPreparedScriptStore.h new file mode 100644 index 00000000000..afc0e85137f --- /dev/null +++ b/vnext/ReactUWP/ChakraPreparedScriptStore.h @@ -0,0 +1,23 @@ +#pragma once +#include + +namespace react { + namespace uwp { + class ChakraPreparedScriptStore : public facebook::jsi::PreparedScriptStore + { + public: + std::unique_ptr tryGetPreparedScript( + const facebook::jsi::ScriptSignature& scriptSignature, + const facebook::jsi::JSRuntimeSignature& runtimeSignature, + const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. + ) noexcept override; + + void persistPreparedScript( + std::shared_ptr preparedScript, + const facebook::jsi::ScriptSignature& scriptMetadata, + const facebook::jsi::JSRuntimeSignature& runtimeMetadata, + const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. + ) noexcept override; + }; + } +} diff --git a/vnext/ReactUWP/ReactUWP.vcxproj b/vnext/ReactUWP/ReactUWP.vcxproj index 5d972e50502..f98e13c2026 100644 --- a/vnext/ReactUWP/ReactUWP.vcxproj +++ b/vnext/ReactUWP/ReactUWP.vcxproj @@ -161,6 +161,7 @@ + @@ -234,6 +235,7 @@ + diff --git a/vnext/ReactUWP/ReactUWP.vcxproj.filters b/vnext/ReactUWP/ReactUWP.vcxproj.filters index b2038d9995c..8b53aad3d04 100644 --- a/vnext/ReactUWP/ReactUWP.vcxproj.filters +++ b/vnext/ReactUWP/ReactUWP.vcxproj.filters @@ -222,6 +222,9 @@ Utils + + Utils + @@ -444,6 +447,9 @@ Utils + + Utils + From cd9871a90b16cf6e3e718a6e526c7bd4de7ba4ed Mon Sep 17 00:00:00 2001 From: Joseph Bui Date: Mon, 17 Jun 2019 13:30:42 -0700 Subject: [PATCH 03/13] added code for script store and tryGetPreparedScript --- vnext/ReactUWP/ChakraPreparedScriptStore.cpp | 29 ++++++++++++++++++++ vnext/ReactUWP/ChakraPreparedScriptStore.h | 5 ++++ vnext/ReactUWP/ChakraScriptStore.cpp | 8 +++++- vnext/ReactUWP/Utils/LocalBundleReader.cpp | 26 ++++++++++++++++++ vnext/ReactUWP/Utils/LocalBundleReader.h | 3 ++ 5 files changed, 70 insertions(+), 1 deletion(-) diff --git a/vnext/ReactUWP/ChakraPreparedScriptStore.cpp b/vnext/ReactUWP/ChakraPreparedScriptStore.cpp index 560310dfad4..6291dd057b5 100644 --- a/vnext/ReactUWP/ChakraPreparedScriptStore.cpp +++ b/vnext/ReactUWP/ChakraPreparedScriptStore.cpp @@ -1,5 +1,11 @@ #include "pch.h" #include "ChakraPreparedScriptStore.h" +#include +#include +#include +#include "unicode.h" + +using namespace winrt; namespace react { namespace uwp { @@ -10,6 +16,10 @@ namespace react { const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. ) noexcept { + if (shouldGetPreparedScript(scriptSignature.version)) + { + return getPreparedScriptAsync(); + } return nullptr; } @@ -20,6 +30,25 @@ namespace react { const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. ) noexcept { + persistPreparedScriptAsync(scriptMetadata.version, preparedScript); + } + + bool ChakraPreparedScriptStore::shouldGetPreparedScript(facebook::jsi::ScriptVersion_t v) noexcept + { + const std::string bundleUrl = "ms-appx:///assets/app.bytecode"; + const winrt::Windows::Foundation::DateTime bytecodeFileCreatedTime = LocalBundleReader::LoadBundleCreatedDateTime(bundleUrl); + const std::uint64_t timestamp = bytecodeFileCreatedTime.time_since_epoch().count(); + + return timestamp > v; + } + + std::unique_ptr ChakraPreparedScriptStore::getPreparedScriptAsync() noexcept + { + return nullptr; + } + void ChakraPreparedScriptStore::persistPreparedScriptAsync(facebook::jsi::ScriptVersion_t v, std::shared_ptr) noexcept + { + auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); } } diff --git a/vnext/ReactUWP/ChakraPreparedScriptStore.h b/vnext/ReactUWP/ChakraPreparedScriptStore.h index afc0e85137f..cd85fd16376 100644 --- a/vnext/ReactUWP/ChakraPreparedScriptStore.h +++ b/vnext/ReactUWP/ChakraPreparedScriptStore.h @@ -1,5 +1,6 @@ #pragma once #include +#include namespace react { namespace uwp { @@ -18,6 +19,10 @@ namespace react { const facebook::jsi::JSRuntimeSignature& runtimeMetadata, const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. ) noexcept override; + private: + bool shouldGetPreparedScript(facebook::jsi::ScriptVersion_t v) noexcept; + std::unique_ptr getPreparedScriptAsync() noexcept; + void persistPreparedScriptAsync(facebook::jsi::ScriptVersion_t v, std::shared_ptr) noexcept; }; } } diff --git a/vnext/ReactUWP/ChakraScriptStore.cpp b/vnext/ReactUWP/ChakraScriptStore.cpp index 3d72fa42843..30ae4420dd7 100644 --- a/vnext/ReactUWP/ChakraScriptStore.cpp +++ b/vnext/ReactUWP/ChakraScriptStore.cpp @@ -1,5 +1,7 @@ #include "pch.h" #include "ChakraScriptStore.h" +#include +#include namespace react { namespace uwp { @@ -13,9 +15,13 @@ namespace react { return versionedBuffer_; } + // Script version = timestamp of bundle file last created facebook::jsi::ScriptVersion_t ChakraScriptStore::getScriptVersion(const std::string& url) noexcept { - facebook::jsi::ScriptVersion_t scriptVersion_ = 0; + const std::string bundleUrl = "ms-appx:///Bundle/App.bundle"; + const winrt::Windows::Foundation::DateTime bundleCreatedTime = LocalBundleReader::LoadBundleCreatedDateTime(bundleUrl); + const std::uint64_t timestamp = bundleCreatedTime.time_since_epoch().count(); + facebook::jsi::ScriptVersion_t scriptVersion_ = timestamp; return scriptVersion_; } diff --git a/vnext/ReactUWP/Utils/LocalBundleReader.cpp b/vnext/ReactUWP/Utils/LocalBundleReader.cpp index 922ed0ae569..0250c052980 100644 --- a/vnext/ReactUWP/Utils/LocalBundleReader.cpp +++ b/vnext/ReactUWP/Utils/LocalBundleReader.cpp @@ -32,6 +32,32 @@ std::string LocalBundleReader::LoadBundle(const std::string& bundlePath) return LoadBundleAsync(bundlePath).get(); } +std::future LocalBundleReader::LoadBundleCreatedDateTimeAsync(const std::string& bundleUri) +{ + winrt::hstring str(facebook::react::unicode::utf8ToUtf16(bundleUri)); + winrt::Windows::Foundation::Uri uri(str); + + co_await winrt::resume_background(); + + try + { + auto file = co_await winrt::Windows::Storage::StorageFile::GetFileFromApplicationUriAsync(uri); + return file.DateCreated(); + } + catch (winrt::hresult_error const& ex) + { + winrt::hresult hr = ex.to_abi(); // HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND). + winrt::hstring message = ex.message(); // The system cannot find the file specified. + winrt::Windows::Foundation::DateTime date; + return date; + } +} + +winrt::Windows::Foundation::DateTime LocalBundleReader::LoadBundleCreatedDateTime(const std::string& bundlePath) +{ + return LoadBundleCreatedDateTimeAsync(bundlePath).get(); +} + StorageFileBigString::StorageFileBigString(const std::string& path) { m_futureBuffer = LocalBundleReader::LoadBundleAsync(path); } diff --git a/vnext/ReactUWP/Utils/LocalBundleReader.h b/vnext/ReactUWP/Utils/LocalBundleReader.h index e2ebbece597..cc2ceafed11 100644 --- a/vnext/ReactUWP/Utils/LocalBundleReader.h +++ b/vnext/ReactUWP/Utils/LocalBundleReader.h @@ -5,6 +5,7 @@ #include #include #include +#include namespace react { namespace uwp { @@ -13,6 +14,8 @@ class LocalBundleReader public: static std::future LoadBundleAsync(const std::string& bundlePath); static std::string LoadBundle(const std::string& bundlePath); + static std::future LoadBundleCreatedDateTimeAsync(const std::string& bundlePath); + static winrt::Windows::Foundation::DateTime LoadBundleCreatedDateTime(const std::string& bundlePath); }; class StorageFileBigString : public facebook::react::JSBigString From d3cb7aa0d559f76c1db4644dfd0ae932d1fd0341 Mon Sep 17 00:00:00 2001 From: Joseph Bui Date: Mon, 17 Jun 2019 16:46:29 -0700 Subject: [PATCH 04/13] added ability to read and write buffer from/to local file --- vnext/ReactUWP/ChakraPreparedScriptStore.cpp | 41 ++++++------ vnext/ReactUWP/ChakraPreparedScriptStore.h | 2 - vnext/ReactUWP/ChakraScriptStore.cpp | 8 +-- vnext/ReactUWP/LocalByteCodeManager.cpp | 66 ++++++++++++++++++++ vnext/ReactUWP/LocalByteCodeManager.h | 31 +++++++++ vnext/ReactUWP/ReactUWP.vcxproj | 6 ++ vnext/ReactUWP/ReactUWP.vcxproj.filters | 6 ++ vnext/ReactUWP/Utils/LocalBundleReader.cpp | 8 +-- vnext/ReactUWP/Utils/LocalBundleReader.h | 6 +- 9 files changed, 141 insertions(+), 33 deletions(-) create mode 100644 vnext/ReactUWP/LocalByteCodeManager.cpp create mode 100644 vnext/ReactUWP/LocalByteCodeManager.h diff --git a/vnext/ReactUWP/ChakraPreparedScriptStore.cpp b/vnext/ReactUWP/ChakraPreparedScriptStore.cpp index 6291dd057b5..7f46afaf5e0 100644 --- a/vnext/ReactUWP/ChakraPreparedScriptStore.cpp +++ b/vnext/ReactUWP/ChakraPreparedScriptStore.cpp @@ -3,22 +3,36 @@ #include #include #include -#include "unicode.h" +#include "LocalByteCodeManager.h" +#include "ChakraJsiRuntime.h" +#include using namespace winrt; namespace react { namespace uwp { - std::unique_ptr ChakraPreparedScriptStore::tryGetPreparedScript( const facebook::jsi::ScriptSignature& scriptSignature, const facebook::jsi::JSRuntimeSignature& runtimeSignature, const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. ) noexcept { + // check if app bundle version is older than or equal to the prepared script version + // if true then just read the buffer from the prepared script and return if (shouldGetPreparedScript(scriptSignature.version)) { - return getPreparedScriptAsync(); + auto buffer = LocalByteCodeManager::LoadBuffer(); + std::unique_ptr bytecodeBuffer( + std::make_unique(buffer.Length()) + ); + + auto dataReader{ winrt::Windows::Storage::Streams::DataReader::FromBuffer(buffer) }; + std::vector buffer_vector(buffer.Length()); + winrt::array_view arrayView{ buffer_vector }; + dataReader.ReadBytes(arrayView); + dataReader.Close(); + + return bytecodeBuffer; } return nullptr; } @@ -30,26 +44,15 @@ namespace react { const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. ) noexcept { - persistPreparedScriptAsync(scriptMetadata.version, preparedScript); + // generate a new bytecode file + LocalByteCodeManager::CreateFile(preparedScript.get()->data()); } bool ChakraPreparedScriptStore::shouldGetPreparedScript(facebook::jsi::ScriptVersion_t v) noexcept { - const std::string bundleUrl = "ms-appx:///assets/app.bytecode"; - const winrt::Windows::Foundation::DateTime bytecodeFileCreatedTime = LocalBundleReader::LoadBundleCreatedDateTime(bundleUrl); - const std::uint64_t timestamp = bytecodeFileCreatedTime.time_since_epoch().count(); - - return timestamp > v; - } - - std::unique_ptr ChakraPreparedScriptStore::getPreparedScriptAsync() noexcept - { - return nullptr; - } - void ChakraPreparedScriptStore::persistPreparedScriptAsync(facebook::jsi::ScriptVersion_t v, std::shared_ptr) noexcept - { - auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); - + const winrt::Windows::Foundation::DateTime createdDateTime = LocalByteCodeManager::LoadCreatedDateTime(); + const std::uint64_t timestamp = createdDateTime.time_since_epoch().count(); + return timestamp >= v; } } } diff --git a/vnext/ReactUWP/ChakraPreparedScriptStore.h b/vnext/ReactUWP/ChakraPreparedScriptStore.h index cd85fd16376..74fa93fcce2 100644 --- a/vnext/ReactUWP/ChakraPreparedScriptStore.h +++ b/vnext/ReactUWP/ChakraPreparedScriptStore.h @@ -21,8 +21,6 @@ namespace react { ) noexcept override; private: bool shouldGetPreparedScript(facebook::jsi::ScriptVersion_t v) noexcept; - std::unique_ptr getPreparedScriptAsync() noexcept; - void persistPreparedScriptAsync(facebook::jsi::ScriptVersion_t v, std::shared_ptr) noexcept; }; } } diff --git a/vnext/ReactUWP/ChakraScriptStore.cpp b/vnext/ReactUWP/ChakraScriptStore.cpp index 30ae4420dd7..392a7f0926f 100644 --- a/vnext/ReactUWP/ChakraScriptStore.cpp +++ b/vnext/ReactUWP/ChakraScriptStore.cpp @@ -9,7 +9,7 @@ namespace react { facebook::jsi::VersionedBuffer ChakraScriptStore::getVersionedScript(const std::string& url) noexcept { facebook::jsi::VersionedBuffer versionedBuffer_; - versionedBuffer_.buffer = 0; + versionedBuffer_.buffer = nullptr; versionedBuffer_.version = 0; return versionedBuffer_; @@ -19,11 +19,9 @@ namespace react { facebook::jsi::ScriptVersion_t ChakraScriptStore::getScriptVersion(const std::string& url) noexcept { const std::string bundleUrl = "ms-appx:///Bundle/App.bundle"; - const winrt::Windows::Foundation::DateTime bundleCreatedTime = LocalBundleReader::LoadBundleCreatedDateTime(bundleUrl); + const winrt::Windows::Foundation::DateTime bundleCreatedTime = LocalBundleReader::LoadBundleCreatedDate(bundleUrl); const std::uint64_t timestamp = bundleCreatedTime.time_since_epoch().count(); - facebook::jsi::ScriptVersion_t scriptVersion_ = timestamp; - - return scriptVersion_; + return timestamp; } } } diff --git a/vnext/ReactUWP/LocalByteCodeManager.cpp b/vnext/ReactUWP/LocalByteCodeManager.cpp new file mode 100644 index 00000000000..2a45de9587f --- /dev/null +++ b/vnext/ReactUWP/LocalByteCodeManager.cpp @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include "pch.h" + +#include "LocalByteCodeManager.h" +#include "unicode.h" +#include + +#if _MSC_VER <= 1913 +// VC 19 (2015-2017.6) cannot optimize co_await/cppwinrt usage +#pragma optimize( "", off ) +#endif + +using namespace winrt; + +namespace react { + namespace uwp { + std::future LocalByteCodeManager::LoadCreatedDateTimeAsync() + { + auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); + co_await winrt::resume_background(); + + try + { + auto file = co_await folder.GetFileAsync(L"app.bytecode"); + return file.DateCreated(); + } + catch (winrt::hresult_error const& ex) + { + winrt::Windows::Foundation::DateTime date; + return date; + } + } + + winrt::Windows::Foundation::DateTime LocalByteCodeManager::LoadCreatedDateTime() + { + return LoadCreatedDateTimeAsync().get(); + } + + std::future LocalByteCodeManager::CreateFileAsync(const uint8_t* buffer) + { + auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); + auto file = co_await folder.CreateFileAsync(L"app.bytecode", Windows::Storage::CreationCollisionOption::ReplaceExisting); + co_await winrt::Windows::Storage::FileIO::WriteBytesAsync(file, winrt::array_view { *buffer }); + } + + void LocalByteCodeManager::CreateFile(const uint8_t* buffer) + { + CreateFileAsync(buffer).get(); + } + + std::future LocalByteCodeManager::LoadBufferAsync() + { + auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); + auto file = co_await folder.GetFileAsync(L"app.bytecode"); + auto buffer = co_await Windows::Storage::FileIO::ReadBufferAsync(file); + return buffer; + } + + Windows::Storage::Streams::IBuffer LocalByteCodeManager::LoadBuffer() + { + return LoadBufferAsync().get(); + } + } +} diff --git a/vnext/ReactUWP/LocalByteCodeManager.h b/vnext/ReactUWP/LocalByteCodeManager.h new file mode 100644 index 00000000000..269b4343913 --- /dev/null +++ b/vnext/ReactUWP/LocalByteCodeManager.h @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#pragma once +#include +#include +#include +#include + +using namespace winrt; + +namespace react { + namespace uwp { + + class LocalByteCodeManager + { + public: + // Get byte code file created date to compare with app bundle file created date + static std::future LoadCreatedDateTimeAsync(); + static winrt::Windows::Foundation::DateTime LoadCreatedDateTime(); + + // Create byte code file to re-use when app bundle did not change + static std::future CreateFileAsync(const uint8_t* buffer); + static void CreateFile(const uint8_t* buffer); + + // Get buffer from byte code file + static std::future LoadBufferAsync(); + static Windows::Storage::Streams::IBuffer LoadBuffer(); + }; + } +} diff --git a/vnext/ReactUWP/ReactUWP.vcxproj b/vnext/ReactUWP/ReactUWP.vcxproj index f98e13c2026..5dc578a6ec6 100644 --- a/vnext/ReactUWP/ReactUWP.vcxproj +++ b/vnext/ReactUWP/ReactUWP.vcxproj @@ -164,6 +164,9 @@ + + true + @@ -242,6 +245,9 @@ + + true + diff --git a/vnext/ReactUWP/ReactUWP.vcxproj.filters b/vnext/ReactUWP/ReactUWP.vcxproj.filters index 8b53aad3d04..5eae0492396 100644 --- a/vnext/ReactUWP/ReactUWP.vcxproj.filters +++ b/vnext/ReactUWP/ReactUWP.vcxproj.filters @@ -225,6 +225,9 @@ Utils + + Utils + @@ -450,6 +453,9 @@ Utils + + Utils + diff --git a/vnext/ReactUWP/Utils/LocalBundleReader.cpp b/vnext/ReactUWP/Utils/LocalBundleReader.cpp index 0250c052980..b340c8b145d 100644 --- a/vnext/ReactUWP/Utils/LocalBundleReader.cpp +++ b/vnext/ReactUWP/Utils/LocalBundleReader.cpp @@ -32,7 +32,7 @@ std::string LocalBundleReader::LoadBundle(const std::string& bundlePath) return LoadBundleAsync(bundlePath).get(); } -std::future LocalBundleReader::LoadBundleCreatedDateTimeAsync(const std::string& bundleUri) +std::future LocalBundleReader::LoadBundleCreatedDateAsync(const std::string& bundleUri) { winrt::hstring str(facebook::react::unicode::utf8ToUtf16(bundleUri)); winrt::Windows::Foundation::Uri uri(str); @@ -46,16 +46,14 @@ std::future LocalBundleReader::LoadBundleC } catch (winrt::hresult_error const& ex) { - winrt::hresult hr = ex.to_abi(); // HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND). - winrt::hstring message = ex.message(); // The system cannot find the file specified. winrt::Windows::Foundation::DateTime date; return date; } } -winrt::Windows::Foundation::DateTime LocalBundleReader::LoadBundleCreatedDateTime(const std::string& bundlePath) +winrt::Windows::Foundation::DateTime LocalBundleReader::LoadBundleCreatedDate(const std::string& bundlePath) { - return LoadBundleCreatedDateTimeAsync(bundlePath).get(); + return LoadBundleCreatedDateAsync(bundlePath).get(); } StorageFileBigString::StorageFileBigString(const std::string& path) { diff --git a/vnext/ReactUWP/Utils/LocalBundleReader.h b/vnext/ReactUWP/Utils/LocalBundleReader.h index cc2ceafed11..d7fc687cdfa 100644 --- a/vnext/ReactUWP/Utils/LocalBundleReader.h +++ b/vnext/ReactUWP/Utils/LocalBundleReader.h @@ -14,8 +14,10 @@ class LocalBundleReader public: static std::future LoadBundleAsync(const std::string& bundlePath); static std::string LoadBundle(const std::string& bundlePath); - static std::future LoadBundleCreatedDateTimeAsync(const std::string& bundlePath); - static winrt::Windows::Foundation::DateTime LoadBundleCreatedDateTime(const std::string& bundlePath); + + // Get app bundle created date to compare with byte code file created date + static std::future LoadBundleCreatedDateAsync(const std::string& bundlePath); + static winrt::Windows::Foundation::DateTime LoadBundleCreatedDate(const std::string& bundlePath); }; class StorageFileBigString : public facebook::react::JSBigString From 1e275eca59306ed00004a4056440bfa5648eb370 Mon Sep 17 00:00:00 2001 From: Joseph Bui Date: Mon, 17 Jun 2019 17:37:06 -0700 Subject: [PATCH 05/13] changed code style to match other files in Utils folder --- vnext/ReactUWP/ChakraPreparedScriptStore.cpp | 90 ++++++++++---------- vnext/ReactUWP/ChakraPreparedScriptStore.h | 42 ++++----- vnext/ReactUWP/ChakraScriptStore.cpp | 35 ++++---- vnext/ReactUWP/ChakraScriptStore.h | 20 ++--- vnext/ReactUWP/LocalByteCodeManager.cpp | 90 ++++++++++---------- vnext/ReactUWP/LocalByteCodeManager.h | 33 ++++--- 6 files changed, 156 insertions(+), 154 deletions(-) diff --git a/vnext/ReactUWP/ChakraPreparedScriptStore.cpp b/vnext/ReactUWP/ChakraPreparedScriptStore.cpp index 7f46afaf5e0..24e68938b4a 100644 --- a/vnext/ReactUWP/ChakraPreparedScriptStore.cpp +++ b/vnext/ReactUWP/ChakraPreparedScriptStore.cpp @@ -9,50 +9,50 @@ using namespace winrt; -namespace react { - namespace uwp { - std::unique_ptr ChakraPreparedScriptStore::tryGetPreparedScript( - const facebook::jsi::ScriptSignature& scriptSignature, - const facebook::jsi::JSRuntimeSignature& runtimeSignature, - const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. - ) noexcept - { - // check if app bundle version is older than or equal to the prepared script version - // if true then just read the buffer from the prepared script and return - if (shouldGetPreparedScript(scriptSignature.version)) - { - auto buffer = LocalByteCodeManager::LoadBuffer(); - std::unique_ptr bytecodeBuffer( - std::make_unique(buffer.Length()) - ); - - auto dataReader{ winrt::Windows::Storage::Streams::DataReader::FromBuffer(buffer) }; - std::vector buffer_vector(buffer.Length()); - winrt::array_view arrayView{ buffer_vector }; - dataReader.ReadBytes(arrayView); - dataReader.Close(); - - return bytecodeBuffer; - } - return nullptr; - } - - void ChakraPreparedScriptStore::persistPreparedScript( - std::shared_ptr preparedScript, - const facebook::jsi::ScriptSignature& scriptMetadata, - const facebook::jsi::JSRuntimeSignature& runtimeMetadata, - const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. - ) noexcept - { - // generate a new bytecode file - LocalByteCodeManager::CreateFile(preparedScript.get()->data()); - } - - bool ChakraPreparedScriptStore::shouldGetPreparedScript(facebook::jsi::ScriptVersion_t v) noexcept - { - const winrt::Windows::Foundation::DateTime createdDateTime = LocalByteCodeManager::LoadCreatedDateTime(); - const std::uint64_t timestamp = createdDateTime.time_since_epoch().count(); - return timestamp >= v; - } +namespace react { namespace uwp { + +std::unique_ptr ChakraPreparedScriptStore::tryGetPreparedScript( + const facebook::jsi::ScriptSignature& scriptSignature, + const facebook::jsi::JSRuntimeSignature& runtimeSignature, + const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. +) noexcept +{ + // check if app bundle version is older than or equal to the prepared script version + // if true then just read the buffer from the prepared script and return + if (shouldGetPreparedScript(scriptSignature.version)) + { + auto buffer = LocalByteCodeManager::LoadBuffer(); + std::unique_ptr bytecodeBuffer( + std::make_unique(buffer.Length()) + ); + + auto dataReader{ winrt::Windows::Storage::Streams::DataReader::FromBuffer(buffer) }; + std::vector buffer_vector(buffer.Length()); + winrt::array_view arrayView{ buffer_vector }; + dataReader.ReadBytes(arrayView); + dataReader.Close(); + + return bytecodeBuffer; } + return nullptr; +} + +void ChakraPreparedScriptStore::persistPreparedScript( + std::shared_ptr preparedScript, + const facebook::jsi::ScriptSignature& scriptMetadata, + const facebook::jsi::JSRuntimeSignature& runtimeMetadata, + const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. +) noexcept +{ + // generate a new bytecode file + LocalByteCodeManager::CreateFile(preparedScript.get()->data()); +} + +bool ChakraPreparedScriptStore::shouldGetPreparedScript(facebook::jsi::ScriptVersion_t v) noexcept +{ + const winrt::Windows::Foundation::DateTime createdDateTime = LocalByteCodeManager::LoadCreatedDateTime(); + const std::uint64_t timestamp = createdDateTime.time_since_epoch().count(); + return timestamp >= v; } + +}} diff --git a/vnext/ReactUWP/ChakraPreparedScriptStore.h b/vnext/ReactUWP/ChakraPreparedScriptStore.h index 74fa93fcce2..c7245926c42 100644 --- a/vnext/ReactUWP/ChakraPreparedScriptStore.h +++ b/vnext/ReactUWP/ChakraPreparedScriptStore.h @@ -2,25 +2,25 @@ #include #include -namespace react { - namespace uwp { - class ChakraPreparedScriptStore : public facebook::jsi::PreparedScriptStore - { - public: - std::unique_ptr tryGetPreparedScript( - const facebook::jsi::ScriptSignature& scriptSignature, - const facebook::jsi::JSRuntimeSignature& runtimeSignature, - const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. - ) noexcept override; +namespace react { namespace uwp { - void persistPreparedScript( - std::shared_ptr preparedScript, - const facebook::jsi::ScriptSignature& scriptMetadata, - const facebook::jsi::JSRuntimeSignature& runtimeMetadata, - const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. - ) noexcept override; - private: - bool shouldGetPreparedScript(facebook::jsi::ScriptVersion_t v) noexcept; - }; - } -} +class ChakraPreparedScriptStore : public facebook::jsi::PreparedScriptStore +{ +public: + std::unique_ptr tryGetPreparedScript( + const facebook::jsi::ScriptSignature& scriptSignature, + const facebook::jsi::JSRuntimeSignature& runtimeSignature, + const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. + ) noexcept override; + + void persistPreparedScript( + std::shared_ptr preparedScript, + const facebook::jsi::ScriptSignature& scriptMetadata, + const facebook::jsi::JSRuntimeSignature& runtimeMetadata, + const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. + ) noexcept override; +private: + bool shouldGetPreparedScript(facebook::jsi::ScriptVersion_t v) noexcept; +}; + +}} diff --git a/vnext/ReactUWP/ChakraScriptStore.cpp b/vnext/ReactUWP/ChakraScriptStore.cpp index 392a7f0926f..9a5eb0e30a7 100644 --- a/vnext/ReactUWP/ChakraScriptStore.cpp +++ b/vnext/ReactUWP/ChakraScriptStore.cpp @@ -3,25 +3,24 @@ #include #include -namespace react { - namespace uwp { +namespace react { namespace uwp { - facebook::jsi::VersionedBuffer ChakraScriptStore::getVersionedScript(const std::string& url) noexcept - { - facebook::jsi::VersionedBuffer versionedBuffer_; - versionedBuffer_.buffer = nullptr; - versionedBuffer_.version = 0; +facebook::jsi::VersionedBuffer ChakraScriptStore::getVersionedScript(const std::string& url) noexcept +{ + facebook::jsi::VersionedBuffer versionedBuffer_; + versionedBuffer_.buffer = nullptr; + versionedBuffer_.version = 0; - return versionedBuffer_; - } + return versionedBuffer_; +} - // Script version = timestamp of bundle file last created - facebook::jsi::ScriptVersion_t ChakraScriptStore::getScriptVersion(const std::string& url) noexcept - { - const std::string bundleUrl = "ms-appx:///Bundle/App.bundle"; - const winrt::Windows::Foundation::DateTime bundleCreatedTime = LocalBundleReader::LoadBundleCreatedDate(bundleUrl); - const std::uint64_t timestamp = bundleCreatedTime.time_since_epoch().count(); - return timestamp; - } - } +// Script version = timestamp of bundle file last created +facebook::jsi::ScriptVersion_t ChakraScriptStore::getScriptVersion(const std::string& url) noexcept +{ + const std::string bundleUrl = "ms-appx:///Bundle/App.bundle"; + const winrt::Windows::Foundation::DateTime bundleCreatedTime = LocalBundleReader::LoadBundleCreatedDate(bundleUrl); + const std::uint64_t timestamp = bundleCreatedTime.time_since_epoch().count(); + return timestamp; } + +}} diff --git a/vnext/ReactUWP/ChakraScriptStore.h b/vnext/ReactUWP/ChakraScriptStore.h index 8a9360fa6b5..ead09a196d5 100644 --- a/vnext/ReactUWP/ChakraScriptStore.h +++ b/vnext/ReactUWP/ChakraScriptStore.h @@ -1,13 +1,13 @@ #pragma once #include -namespace react { - namespace uwp { - class ChakraScriptStore : public facebook::jsi::ScriptStore - { - public: - facebook::jsi::VersionedBuffer getVersionedScript(const std::string& url) noexcept override; - facebook::jsi::ScriptVersion_t getScriptVersion(const std::string& url) noexcept override; - }; - } -} +namespace react { namespace uwp { + +class ChakraScriptStore : public facebook::jsi::ScriptStore +{ +public: + facebook::jsi::VersionedBuffer getVersionedScript(const std::string& url) noexcept override; + facebook::jsi::ScriptVersion_t getScriptVersion(const std::string& url) noexcept override; +}; + +}} diff --git a/vnext/ReactUWP/LocalByteCodeManager.cpp b/vnext/ReactUWP/LocalByteCodeManager.cpp index 2a45de9587f..30cc142131a 100644 --- a/vnext/ReactUWP/LocalByteCodeManager.cpp +++ b/vnext/ReactUWP/LocalByteCodeManager.cpp @@ -14,53 +14,57 @@ using namespace winrt; -namespace react { - namespace uwp { - std::future LocalByteCodeManager::LoadCreatedDateTimeAsync() - { - auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); - co_await winrt::resume_background(); +namespace react { namespace uwp { - try - { - auto file = co_await folder.GetFileAsync(L"app.bytecode"); - return file.DateCreated(); - } - catch (winrt::hresult_error const& ex) - { - winrt::Windows::Foundation::DateTime date; - return date; - } - } +std::future LocalByteCodeManager::LoadCreatedDateTimeAsync() +{ + auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); + co_await winrt::resume_background(); - winrt::Windows::Foundation::DateTime LocalByteCodeManager::LoadCreatedDateTime() - { - return LoadCreatedDateTimeAsync().get(); - } + try + { + auto file = co_await folder.GetFileAsync(L"app.bytecode"); + return file.DateCreated(); + } + catch (winrt::hresult_error const& ex) + { + winrt::Windows::Foundation::DateTime date; + return date; + } +} - std::future LocalByteCodeManager::CreateFileAsync(const uint8_t* buffer) - { - auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); - auto file = co_await folder.CreateFileAsync(L"app.bytecode", Windows::Storage::CreationCollisionOption::ReplaceExisting); - co_await winrt::Windows::Storage::FileIO::WriteBytesAsync(file, winrt::array_view { *buffer }); - } +winrt::Windows::Foundation::DateTime LocalByteCodeManager::LoadCreatedDateTime() +{ + return LoadCreatedDateTimeAsync().get(); +} - void LocalByteCodeManager::CreateFile(const uint8_t* buffer) - { - CreateFileAsync(buffer).get(); - } +std::future LocalByteCodeManager::CreateFileAsync(const uint8_t* buffer) +{ + auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); + co_await winrt::resume_background(); - std::future LocalByteCodeManager::LoadBufferAsync() - { - auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); - auto file = co_await folder.GetFileAsync(L"app.bytecode"); - auto buffer = co_await Windows::Storage::FileIO::ReadBufferAsync(file); - return buffer; - } + auto file = co_await folder.CreateFileAsync(L"app.bytecode", Windows::Storage::CreationCollisionOption::ReplaceExisting); + co_await winrt::Windows::Storage::FileIO::WriteBytesAsync(file, winrt::array_view { *buffer }); +} - Windows::Storage::Streams::IBuffer LocalByteCodeManager::LoadBuffer() - { - return LoadBufferAsync().get(); - } - } +void LocalByteCodeManager::CreateFile(const uint8_t* buffer) +{ + CreateFileAsync(buffer).get(); } + +std::future LocalByteCodeManager::LoadBufferAsync() +{ + auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); + co_await winrt::resume_background(); + + auto file = co_await folder.GetFileAsync(L"app.bytecode"); + auto buffer = co_await Windows::Storage::FileIO::ReadBufferAsync(file); + return buffer; +} + +Windows::Storage::Streams::IBuffer LocalByteCodeManager::LoadBuffer() +{ + return LoadBufferAsync().get(); +} + +}} diff --git a/vnext/ReactUWP/LocalByteCodeManager.h b/vnext/ReactUWP/LocalByteCodeManager.h index 269b4343913..e10bf09a9ce 100644 --- a/vnext/ReactUWP/LocalByteCodeManager.h +++ b/vnext/ReactUWP/LocalByteCodeManager.h @@ -9,23 +9,22 @@ using namespace winrt; -namespace react { - namespace uwp { +namespace react { namespace uwp { - class LocalByteCodeManager - { - public: - // Get byte code file created date to compare with app bundle file created date - static std::future LoadCreatedDateTimeAsync(); - static winrt::Windows::Foundation::DateTime LoadCreatedDateTime(); +class LocalByteCodeManager +{ +public: + // Get byte code file created date to compare with app bundle file created date + static std::future LoadCreatedDateTimeAsync(); + static winrt::Windows::Foundation::DateTime LoadCreatedDateTime(); - // Create byte code file to re-use when app bundle did not change - static std::future CreateFileAsync(const uint8_t* buffer); - static void CreateFile(const uint8_t* buffer); + // Create byte code file to re-use when app bundle did not change + static std::future CreateFileAsync(const uint8_t* buffer); + static void CreateFile(const uint8_t* buffer); - // Get buffer from byte code file - static std::future LoadBufferAsync(); - static Windows::Storage::Streams::IBuffer LoadBuffer(); - }; - } -} + // Get buffer from byte code file + static std::future LoadBufferAsync(); + static Windows::Storage::Streams::IBuffer LoadBuffer(); +}; + +}} From 40b0fd833f3d56ef70c95fdc79fbc1a291cb8bea Mon Sep 17 00:00:00 2001 From: Joseph Bui Date: Tue, 18 Jun 2019 17:11:19 -0700 Subject: [PATCH 06/13] made writing bytecode generate appropriately sized file, removed wrappers from bytecode manager --- vnext/ReactUWP/ChakraPreparedScriptStore.cpp | 9 +++++--- vnext/ReactUWP/LocalByteCodeManager.cpp | 22 ++++---------------- vnext/ReactUWP/LocalByteCodeManager.h | 5 +---- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/vnext/ReactUWP/ChakraPreparedScriptStore.cpp b/vnext/ReactUWP/ChakraPreparedScriptStore.cpp index 24e68938b4a..e0d685fa024 100644 --- a/vnext/ReactUWP/ChakraPreparedScriptStore.cpp +++ b/vnext/ReactUWP/ChakraPreparedScriptStore.cpp @@ -21,7 +21,7 @@ std::unique_ptr ChakraPreparedScriptStore::tryGetPr // if true then just read the buffer from the prepared script and return if (shouldGetPreparedScript(scriptSignature.version)) { - auto buffer = LocalByteCodeManager::LoadBuffer(); + auto buffer = LocalByteCodeManager::LoadBufferAsync().get(); std::unique_ptr bytecodeBuffer( std::make_unique(buffer.Length()) ); @@ -44,13 +44,16 @@ void ChakraPreparedScriptStore::persistPreparedScript( const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. ) noexcept { + auto size = preparedScript->size(); + auto data = preparedScript->data(); + // generate a new bytecode file - LocalByteCodeManager::CreateFile(preparedScript.get()->data()); + LocalByteCodeManager::CreateFileAsync(size, data); } bool ChakraPreparedScriptStore::shouldGetPreparedScript(facebook::jsi::ScriptVersion_t v) noexcept { - const winrt::Windows::Foundation::DateTime createdDateTime = LocalByteCodeManager::LoadCreatedDateTime(); + const winrt::Windows::Foundation::DateTime createdDateTime = LocalByteCodeManager::LoadCreatedDateTimeAsync().get(); const std::uint64_t timestamp = createdDateTime.time_since_epoch().count(); return timestamp >= v; } diff --git a/vnext/ReactUWP/LocalByteCodeManager.cpp b/vnext/ReactUWP/LocalByteCodeManager.cpp index 30cc142131a..b68b7b47a99 100644 --- a/vnext/ReactUWP/LocalByteCodeManager.cpp +++ b/vnext/ReactUWP/LocalByteCodeManager.cpp @@ -32,24 +32,15 @@ std::future LocalByteCodeManager::LoadCrea return date; } } - -winrt::Windows::Foundation::DateTime LocalByteCodeManager::LoadCreatedDateTime() -{ - return LoadCreatedDateTimeAsync().get(); -} - -std::future LocalByteCodeManager::CreateFileAsync(const uint8_t* buffer) +std::future LocalByteCodeManager::CreateFileAsync(size_t size, const uint8_t* buffer) { auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); co_await winrt::resume_background(); auto file = co_await folder.CreateFileAsync(L"app.bytecode", Windows::Storage::CreationCollisionOption::ReplaceExisting); - co_await winrt::Windows::Storage::FileIO::WriteBytesAsync(file, winrt::array_view { *buffer }); -} - -void LocalByteCodeManager::CreateFile(const uint8_t* buffer) -{ - CreateFileAsync(buffer).get(); + std::unique_ptr> bytecodeBuffer = std::make_unique>(size); + bytecodeBuffer->push_back(*buffer); + co_await winrt::Windows::Storage::FileIO::WriteBytesAsync(file, *bytecodeBuffer); } std::future LocalByteCodeManager::LoadBufferAsync() @@ -62,9 +53,4 @@ std::future LocalByteCodeManager::LoadBuffer return buffer; } -Windows::Storage::Streams::IBuffer LocalByteCodeManager::LoadBuffer() -{ - return LoadBufferAsync().get(); -} - }} diff --git a/vnext/ReactUWP/LocalByteCodeManager.h b/vnext/ReactUWP/LocalByteCodeManager.h index e10bf09a9ce..c041517f7f7 100644 --- a/vnext/ReactUWP/LocalByteCodeManager.h +++ b/vnext/ReactUWP/LocalByteCodeManager.h @@ -16,15 +16,12 @@ class LocalByteCodeManager public: // Get byte code file created date to compare with app bundle file created date static std::future LoadCreatedDateTimeAsync(); - static winrt::Windows::Foundation::DateTime LoadCreatedDateTime(); // Create byte code file to re-use when app bundle did not change - static std::future CreateFileAsync(const uint8_t* buffer); - static void CreateFile(const uint8_t* buffer); + static std::future CreateFileAsync(size_t size, const uint8_t* buffer); // Get buffer from byte code file static std::future LoadBufferAsync(); - static Windows::Storage::Streams::IBuffer LoadBuffer(); }; }} From 9174f3397c6716199ea8b5127f847df961eec254 Mon Sep 17 00:00:00 2001 From: Joseph Bui Date: Wed, 19 Jun 2019 14:00:12 -0700 Subject: [PATCH 07/13] made reading and writing work, removed unneeded wrapper --- vnext/ReactUWP/Base/UwpReactInstance.cpp | 13 +- vnext/ReactUWP/ChakraPreparedScriptStore.cpp | 61 --------- vnext/ReactUWP/ChakraPreparedScriptStore.h | 26 ---- vnext/ReactUWP/ChakraScriptStore.cpp | 26 ---- vnext/ReactUWP/LocalByteCodeManager.cpp | 56 -------- vnext/ReactUWP/LocalByteCodeManager.h | 27 ---- vnext/ReactUWP/ReactUWP.vcxproj | 14 +- vnext/ReactUWP/ReactUWP.vcxproj.filters | 14 +- vnext/ReactUWP/Utils/LocalBundleReader.cpp | 24 ---- vnext/ReactUWP/Utils/LocalBundleReader.h | 4 - vnext/ReactUWP/UwpPreparedScriptStore.cpp | 122 ++++++++++++++++++ vnext/ReactUWP/UwpPreparedScriptStore.h | 46 +++++++ vnext/ReactUWP/UwpScriptStore.cpp | 46 +++++++ .../{ChakraScriptStore.h => UwpScriptStore.h} | 5 +- vnext/include/ReactUWP/IReactInstance.h | 3 + 15 files changed, 238 insertions(+), 249 deletions(-) delete mode 100644 vnext/ReactUWP/ChakraPreparedScriptStore.cpp delete mode 100644 vnext/ReactUWP/ChakraPreparedScriptStore.h delete mode 100644 vnext/ReactUWP/ChakraScriptStore.cpp delete mode 100644 vnext/ReactUWP/LocalByteCodeManager.cpp delete mode 100644 vnext/ReactUWP/LocalByteCodeManager.h create mode 100644 vnext/ReactUWP/UwpPreparedScriptStore.cpp create mode 100644 vnext/ReactUWP/UwpPreparedScriptStore.h create mode 100644 vnext/ReactUWP/UwpScriptStore.cpp rename vnext/ReactUWP/{ChakraScriptStore.h => UwpScriptStore.h} (59%) diff --git a/vnext/ReactUWP/Base/UwpReactInstance.cpp b/vnext/ReactUWP/Base/UwpReactInstance.cpp index 4fcd9c43a51..ea9c92ba624 100644 --- a/vnext/ReactUWP/Base/UwpReactInstance.cpp +++ b/vnext/ReactUWP/Base/UwpReactInstance.cpp @@ -63,8 +63,8 @@ #include #include -#include -#include +#include +#include #if !defined(OSS_RN) #include "ChakraJSIRuntimeHolder.h" @@ -276,8 +276,13 @@ void UwpReactInstance::Start(const std::shared_ptr& spThis, cons #if !defined(OSS_RN) if (settings.UseJsi) { - std::unique_ptr scriptStore = std::make_unique(); - std::unique_ptr preparedScriptStore = std::make_unique(); + std::unique_ptr scriptStore = nullptr; + std::unique_ptr preparedScriptStore = nullptr; + + if (settings.EnableByteCodeCacheing || !settings.ByteCodeFileUri.empty()) { + scriptStore = std::make_unique(); + preparedScriptStore = std::make_unique(winrt::to_hstring(settings.ByteCodeFileUri)); + } devSettings->jsiRuntimeHolder = std::make_shared( devSettings, jsQueue, diff --git a/vnext/ReactUWP/ChakraPreparedScriptStore.cpp b/vnext/ReactUWP/ChakraPreparedScriptStore.cpp deleted file mode 100644 index e0d685fa024..00000000000 --- a/vnext/ReactUWP/ChakraPreparedScriptStore.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "pch.h" -#include "ChakraPreparedScriptStore.h" -#include -#include -#include -#include "LocalByteCodeManager.h" -#include "ChakraJsiRuntime.h" -#include - -using namespace winrt; - -namespace react { namespace uwp { - -std::unique_ptr ChakraPreparedScriptStore::tryGetPreparedScript( - const facebook::jsi::ScriptSignature& scriptSignature, - const facebook::jsi::JSRuntimeSignature& runtimeSignature, - const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. -) noexcept -{ - // check if app bundle version is older than or equal to the prepared script version - // if true then just read the buffer from the prepared script and return - if (shouldGetPreparedScript(scriptSignature.version)) - { - auto buffer = LocalByteCodeManager::LoadBufferAsync().get(); - std::unique_ptr bytecodeBuffer( - std::make_unique(buffer.Length()) - ); - - auto dataReader{ winrt::Windows::Storage::Streams::DataReader::FromBuffer(buffer) }; - std::vector buffer_vector(buffer.Length()); - winrt::array_view arrayView{ buffer_vector }; - dataReader.ReadBytes(arrayView); - dataReader.Close(); - - return bytecodeBuffer; - } - return nullptr; -} - -void ChakraPreparedScriptStore::persistPreparedScript( - std::shared_ptr preparedScript, - const facebook::jsi::ScriptSignature& scriptMetadata, - const facebook::jsi::JSRuntimeSignature& runtimeMetadata, - const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. -) noexcept -{ - auto size = preparedScript->size(); - auto data = preparedScript->data(); - - // generate a new bytecode file - LocalByteCodeManager::CreateFileAsync(size, data); -} - -bool ChakraPreparedScriptStore::shouldGetPreparedScript(facebook::jsi::ScriptVersion_t v) noexcept -{ - const winrt::Windows::Foundation::DateTime createdDateTime = LocalByteCodeManager::LoadCreatedDateTimeAsync().get(); - const std::uint64_t timestamp = createdDateTime.time_since_epoch().count(); - return timestamp >= v; -} - -}} diff --git a/vnext/ReactUWP/ChakraPreparedScriptStore.h b/vnext/ReactUWP/ChakraPreparedScriptStore.h deleted file mode 100644 index c7245926c42..00000000000 --- a/vnext/ReactUWP/ChakraPreparedScriptStore.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include -#include - -namespace react { namespace uwp { - -class ChakraPreparedScriptStore : public facebook::jsi::PreparedScriptStore -{ -public: - std::unique_ptr tryGetPreparedScript( - const facebook::jsi::ScriptSignature& scriptSignature, - const facebook::jsi::JSRuntimeSignature& runtimeSignature, - const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. - ) noexcept override; - - void persistPreparedScript( - std::shared_ptr preparedScript, - const facebook::jsi::ScriptSignature& scriptMetadata, - const facebook::jsi::JSRuntimeSignature& runtimeMetadata, - const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. - ) noexcept override; -private: - bool shouldGetPreparedScript(facebook::jsi::ScriptVersion_t v) noexcept; -}; - -}} diff --git a/vnext/ReactUWP/ChakraScriptStore.cpp b/vnext/ReactUWP/ChakraScriptStore.cpp deleted file mode 100644 index 9a5eb0e30a7..00000000000 --- a/vnext/ReactUWP/ChakraScriptStore.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "pch.h" -#include "ChakraScriptStore.h" -#include -#include - -namespace react { namespace uwp { - -facebook::jsi::VersionedBuffer ChakraScriptStore::getVersionedScript(const std::string& url) noexcept -{ - facebook::jsi::VersionedBuffer versionedBuffer_; - versionedBuffer_.buffer = nullptr; - versionedBuffer_.version = 0; - - return versionedBuffer_; -} - -// Script version = timestamp of bundle file last created -facebook::jsi::ScriptVersion_t ChakraScriptStore::getScriptVersion(const std::string& url) noexcept -{ - const std::string bundleUrl = "ms-appx:///Bundle/App.bundle"; - const winrt::Windows::Foundation::DateTime bundleCreatedTime = LocalBundleReader::LoadBundleCreatedDate(bundleUrl); - const std::uint64_t timestamp = bundleCreatedTime.time_since_epoch().count(); - return timestamp; -} - -}} diff --git a/vnext/ReactUWP/LocalByteCodeManager.cpp b/vnext/ReactUWP/LocalByteCodeManager.cpp deleted file mode 100644 index b68b7b47a99..00000000000 --- a/vnext/ReactUWP/LocalByteCodeManager.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "pch.h" - -#include "LocalByteCodeManager.h" -#include "unicode.h" -#include - -#if _MSC_VER <= 1913 -// VC 19 (2015-2017.6) cannot optimize co_await/cppwinrt usage -#pragma optimize( "", off ) -#endif - -using namespace winrt; - -namespace react { namespace uwp { - -std::future LocalByteCodeManager::LoadCreatedDateTimeAsync() -{ - auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); - co_await winrt::resume_background(); - - try - { - auto file = co_await folder.GetFileAsync(L"app.bytecode"); - return file.DateCreated(); - } - catch (winrt::hresult_error const& ex) - { - winrt::Windows::Foundation::DateTime date; - return date; - } -} -std::future LocalByteCodeManager::CreateFileAsync(size_t size, const uint8_t* buffer) -{ - auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); - co_await winrt::resume_background(); - - auto file = co_await folder.CreateFileAsync(L"app.bytecode", Windows::Storage::CreationCollisionOption::ReplaceExisting); - std::unique_ptr> bytecodeBuffer = std::make_unique>(size); - bytecodeBuffer->push_back(*buffer); - co_await winrt::Windows::Storage::FileIO::WriteBytesAsync(file, *bytecodeBuffer); -} - -std::future LocalByteCodeManager::LoadBufferAsync() -{ - auto folder = Windows::Storage::ApplicationData::Current().LocalCacheFolder(); - co_await winrt::resume_background(); - - auto file = co_await folder.GetFileAsync(L"app.bytecode"); - auto buffer = co_await Windows::Storage::FileIO::ReadBufferAsync(file); - return buffer; -} - -}} diff --git a/vnext/ReactUWP/LocalByteCodeManager.h b/vnext/ReactUWP/LocalByteCodeManager.h deleted file mode 100644 index c041517f7f7..00000000000 --- a/vnext/ReactUWP/LocalByteCodeManager.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#pragma once -#include -#include -#include -#include - -using namespace winrt; - -namespace react { namespace uwp { - -class LocalByteCodeManager -{ -public: - // Get byte code file created date to compare with app bundle file created date - static std::future LoadCreatedDateTimeAsync(); - - // Create byte code file to re-use when app bundle did not change - static std::future CreateFileAsync(size_t size, const uint8_t* buffer); - - // Get buffer from byte code file - static std::future LoadBufferAsync(); -}; - -}} diff --git a/vnext/ReactUWP/ReactUWP.vcxproj b/vnext/ReactUWP/ReactUWP.vcxproj index 5dc578a6ec6..a9d6b39eae3 100644 --- a/vnext/ReactUWP/ReactUWP.vcxproj +++ b/vnext/ReactUWP/ReactUWP.vcxproj @@ -161,12 +161,9 @@ - - + + - - true - @@ -238,16 +235,13 @@ - - + + - - true - diff --git a/vnext/ReactUWP/ReactUWP.vcxproj.filters b/vnext/ReactUWP/ReactUWP.vcxproj.filters index 5eae0492396..b934f620136 100644 --- a/vnext/ReactUWP/ReactUWP.vcxproj.filters +++ b/vnext/ReactUWP/ReactUWP.vcxproj.filters @@ -219,13 +219,10 @@ Views - + Utils - - Utils - - + Utils @@ -447,13 +444,10 @@ Views - - Utils - - + Utils - + Utils diff --git a/vnext/ReactUWP/Utils/LocalBundleReader.cpp b/vnext/ReactUWP/Utils/LocalBundleReader.cpp index b340c8b145d..922ed0ae569 100644 --- a/vnext/ReactUWP/Utils/LocalBundleReader.cpp +++ b/vnext/ReactUWP/Utils/LocalBundleReader.cpp @@ -32,30 +32,6 @@ std::string LocalBundleReader::LoadBundle(const std::string& bundlePath) return LoadBundleAsync(bundlePath).get(); } -std::future LocalBundleReader::LoadBundleCreatedDateAsync(const std::string& bundleUri) -{ - winrt::hstring str(facebook::react::unicode::utf8ToUtf16(bundleUri)); - winrt::Windows::Foundation::Uri uri(str); - - co_await winrt::resume_background(); - - try - { - auto file = co_await winrt::Windows::Storage::StorageFile::GetFileFromApplicationUriAsync(uri); - return file.DateCreated(); - } - catch (winrt::hresult_error const& ex) - { - winrt::Windows::Foundation::DateTime date; - return date; - } -} - -winrt::Windows::Foundation::DateTime LocalBundleReader::LoadBundleCreatedDate(const std::string& bundlePath) -{ - return LoadBundleCreatedDateAsync(bundlePath).get(); -} - StorageFileBigString::StorageFileBigString(const std::string& path) { m_futureBuffer = LocalBundleReader::LoadBundleAsync(path); } diff --git a/vnext/ReactUWP/Utils/LocalBundleReader.h b/vnext/ReactUWP/Utils/LocalBundleReader.h index d7fc687cdfa..2660e6c64f3 100644 --- a/vnext/ReactUWP/Utils/LocalBundleReader.h +++ b/vnext/ReactUWP/Utils/LocalBundleReader.h @@ -14,10 +14,6 @@ class LocalBundleReader public: static std::future LoadBundleAsync(const std::string& bundlePath); static std::string LoadBundle(const std::string& bundlePath); - - // Get app bundle created date to compare with byte code file created date - static std::future LoadBundleCreatedDateAsync(const std::string& bundlePath); - static winrt::Windows::Foundation::DateTime LoadBundleCreatedDate(const std::string& bundlePath); }; class StorageFileBigString : public facebook::react::JSBigString diff --git a/vnext/ReactUWP/UwpPreparedScriptStore.cpp b/vnext/ReactUWP/UwpPreparedScriptStore.cpp new file mode 100644 index 00000000000..189699da31e --- /dev/null +++ b/vnext/ReactUWP/UwpPreparedScriptStore.cpp @@ -0,0 +1,122 @@ +#include "pch.h" +#include "UwpPreparedScriptStore.h" +#include +#include +#include +#include "ChakraJsiRuntime.h" +#include +#include "unicode.h" +#include "jsi/jsi.h" + +#if _MSC_VER <= 1913 +// VC 19 (2015-2017.6) cannot optimize co_await/cppwinrt usage +#pragma optimize( "", off ) +#endif + +using namespace winrt::Windows; + +namespace react { namespace uwp { + UwpPreparedScriptStore::UwpPreparedScriptStore(winrt::hstring uri) + { + if (!uri.empty()) + { + auto file = Storage::ApplicationData::Current().LocalFolder().TryGetItemAsync(uri).get(); + if (file) + { + m_byteCodeFileUri = uri; + } + } + } + +std::unique_ptr UwpPreparedScriptStore::tryGetPreparedScript( + const facebook::jsi::ScriptSignature& scriptSignature, + const facebook::jsi::JSRuntimeSignature& runtimeSignature, + const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. +) noexcept +{ + // check if app bundle version is older than or equal to the prepared script version + // if true then just read the buffer from the prepared script and return + if (shouldGetPreparedScript(scriptSignature.version)) + { + auto buffer = ByteCodeManager::ReadByteCodeFileAsync(m_byteCodeFileUri).get(); + auto bytecodeBuffer(std::make_unique(buffer.Length())); + auto dataReader{ Storage::Streams::DataReader::FromBuffer(buffer) }; + dataReader.ReadBytes(winrt::array_view { &bytecodeBuffer->data()[0], &bytecodeBuffer->data()[bytecodeBuffer->size()] }); + dataReader.Close(); + + return bytecodeBuffer; + } + return nullptr; +} + +void UwpPreparedScriptStore::persistPreparedScript( + std::shared_ptr preparedScript, + const facebook::jsi::ScriptSignature& scriptMetadata, + const facebook::jsi::JSRuntimeSignature& runtimeMetadata, + const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. +) noexcept +{ + // generate a new bytecode file + ByteCodeManager::CreateByteCodeFileAsync(preparedScript); +} + +bool UwpPreparedScriptStore::shouldGetPreparedScript(facebook::jsi::ScriptVersion_t version) noexcept +{ + auto createdDateTime = ByteCodeManager::GetByteCodeFileCreatedDateAsync(m_byteCodeFileUri).get(); + std::uint64_t timestamp = createdDateTime.time_since_epoch().count(); + + // try using default bytecode file url if given url is older than app bundle + if (timestamp < version && !m_byteCodeFileUri.empty()) + { + m_byteCodeFileUri = nullptr; + return shouldGetPreparedScript(version); + } + + return timestamp >= version; +} + +std::future ByteCodeManager::GetByteCodeFileCreatedDateAsync(winrt::hstring fileName) +{ + co_await winrt::resume_background(); + + try + { + auto file = fileName.empty() ? + co_await Storage::ApplicationData::Current().LocalCacheFolder().GetFileAsync(L"app.bytecode") : + co_await Storage::StorageFile::GetFileFromApplicationUriAsync(Foundation::Uri(fileName)); + return file.DateCreated(); + } + catch (winrt::hresult_error const& ex) + { + Foundation::DateTime date; + return date; + } +} + +winrt::fire_and_forget ByteCodeManager::CreateByteCodeFileAsync(std::shared_ptr preparedScript) +{ + auto folder = Storage::ApplicationData::Current().LocalCacheFolder(); + co_await winrt::resume_background(); + + auto file = co_await folder.CreateFileAsync(L"app.bytecode", Storage::CreationCollisionOption::ReplaceExisting); + Storage::FileIO::WriteBytesAsync(file, winrt::array_view{ &preparedScript->data()[0], &preparedScript->data()[preparedScript->size()] }); +} + +std::future ByteCodeManager::ReadByteCodeFileAsync(winrt::hstring fileName) +{ + co_await winrt::resume_background(); + try + { + auto file = fileName.empty() ? + co_await Storage::ApplicationData::Current().LocalCacheFolder().GetFileAsync(L"app.bytecode") : + co_await Storage::StorageFile::GetFileFromApplicationUriAsync(Foundation::Uri(fileName)); + auto buffer = co_await Storage::FileIO::ReadBufferAsync(file); + return buffer; + } + catch (winrt::hresult_error const& ex) + { + return nullptr; + } +} + +}} diff --git a/vnext/ReactUWP/UwpPreparedScriptStore.h b/vnext/ReactUWP/UwpPreparedScriptStore.h new file mode 100644 index 00000000000..4c03a962f2a --- /dev/null +++ b/vnext/ReactUWP/UwpPreparedScriptStore.h @@ -0,0 +1,46 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include "jsi/jsi.h" + +namespace react { namespace uwp { + +class UwpPreparedScriptStore : public facebook::jsi::PreparedScriptStore +{ +public: + UwpPreparedScriptStore(winrt::hstring uri); + std::unique_ptr tryGetPreparedScript( + const facebook::jsi::ScriptSignature& scriptSignature, + const facebook::jsi::JSRuntimeSignature& runtimeSignature, + const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. + ) noexcept override; + + void persistPreparedScript( + std::shared_ptr preparedScript, + const facebook::jsi::ScriptSignature& scriptMetadata, + const facebook::jsi::JSRuntimeSignature& runtimeMetadata, + const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. + ) noexcept override; +private: + bool shouldGetPreparedScript(facebook::jsi::ScriptVersion_t v) noexcept; + winrt::hstring m_byteCodeFileUri; +}; + +class ByteCodeManager +{ +public: + // Get byte code file created date to compare with app bundle file created date + static std::future GetByteCodeFileCreatedDateAsync(winrt::hstring fileName); + + // Create byte code file to re-use when app bundle did not change + static winrt::fire_and_forget CreateByteCodeFileAsync(std::shared_ptr preparedScript); + + // Read from byte code file + static std::future ReadByteCodeFileAsync(winrt::hstring fileName); +}; + +}} diff --git a/vnext/ReactUWP/UwpScriptStore.cpp b/vnext/ReactUWP/UwpScriptStore.cpp new file mode 100644 index 00000000000..18dd83a7e39 --- /dev/null +++ b/vnext/ReactUWP/UwpScriptStore.cpp @@ -0,0 +1,46 @@ +#include "pch.h" +#include "UwpScriptStore.h" +#include +#include +#include "unicode.h" + +namespace react { namespace uwp { + +facebook::jsi::VersionedBuffer UwpScriptStore::getVersionedScript(const std::string& url) noexcept +{ + facebook::jsi::VersionedBuffer versionedBuffer_; + versionedBuffer_.buffer = nullptr; + versionedBuffer_.version = 0; + + return versionedBuffer_; +} + +// Script version = timestamp of bundle file last created +facebook::jsi::ScriptVersion_t UwpScriptStore::getScriptVersion(const std::string& url) noexcept +{ + const std::string bundleUrl = "ms-appx:///Bundle/" + url + ".bundle"; + const winrt::Windows::Foundation::DateTime bundleCreatedTime = getBundleCreatedDate(bundleUrl).get(); + const std::uint64_t timestamp = bundleCreatedTime.time_since_epoch().count(); + return timestamp; +} + +std::future UwpScriptStore::getBundleCreatedDate(const std::string& bundleUri) +{ + winrt::hstring str(facebook::react::unicode::utf8ToUtf16(bundleUri)); + winrt::Windows::Foundation::Uri uri(str); + + co_await winrt::resume_background(); + + try + { + auto file = co_await winrt::Windows::Storage::StorageFile::GetFileFromApplicationUriAsync(uri); + return file.DateCreated(); + } + catch (winrt::hresult_error const& ex) + { + winrt::Windows::Foundation::DateTime date; + return date; + } +} + +}} diff --git a/vnext/ReactUWP/ChakraScriptStore.h b/vnext/ReactUWP/UwpScriptStore.h similarity index 59% rename from vnext/ReactUWP/ChakraScriptStore.h rename to vnext/ReactUWP/UwpScriptStore.h index ead09a196d5..7937f393342 100644 --- a/vnext/ReactUWP/ChakraScriptStore.h +++ b/vnext/ReactUWP/UwpScriptStore.h @@ -1,13 +1,16 @@ #pragma once #include +#include namespace react { namespace uwp { -class ChakraScriptStore : public facebook::jsi::ScriptStore +class UwpScriptStore : public facebook::jsi::ScriptStore { public: facebook::jsi::VersionedBuffer getVersionedScript(const std::string& url) noexcept override; facebook::jsi::ScriptVersion_t getScriptVersion(const std::string& url) noexcept override; +private: + std::future getBundleCreatedDate(const std::string& bundlePath); }; }} diff --git a/vnext/include/ReactUWP/IReactInstance.h b/vnext/include/ReactUWP/IReactInstance.h index c47637fdd86..09581d4dee0 100644 --- a/vnext/include/ReactUWP/IReactInstance.h +++ b/vnext/include/ReactUWP/IReactInstance.h @@ -30,6 +30,9 @@ struct ReactInstanceSettings bool UseDirectDebugger{ false }; bool UseJsi { true }; bool EnableJITCompilation { true }; + bool EnableByteCodeCacheing { true }; + + std::string ByteCodeFileUri; std::string DebugHost; std::string DebugBundlePath; facebook::react::NativeLoggingHook LoggingCallback; From eb540ce090a698e4f5a8337e973e8a7956dd6238 Mon Sep 17 00:00:00 2001 From: Joseph Bui Date: Wed, 19 Jun 2019 14:05:14 -0700 Subject: [PATCH 08/13] set default bytecode caching to false --- vnext/include/ReactUWP/IReactInstance.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vnext/include/ReactUWP/IReactInstance.h b/vnext/include/ReactUWP/IReactInstance.h index 09581d4dee0..640e0581d3b 100644 --- a/vnext/include/ReactUWP/IReactInstance.h +++ b/vnext/include/ReactUWP/IReactInstance.h @@ -30,7 +30,7 @@ struct ReactInstanceSettings bool UseDirectDebugger{ false }; bool UseJsi { true }; bool EnableJITCompilation { true }; - bool EnableByteCodeCacheing { true }; + bool EnableByteCodeCacheing { false }; std::string ByteCodeFileUri; std::string DebugHost; From 506c40b2a6b89d9a5368ba24cf5c0665fc625ddf Mon Sep 17 00:00:00 2001 From: Stephen Crain Date: Thu, 20 Jun 2019 09:16:26 -0700 Subject: [PATCH 09/13] address comments --- vnext/ReactUWP/Utils/LocalBundleReader.h | 1 - vnext/ReactUWP/UwpPreparedScriptStore.cpp | 115 ++++++++++------------ vnext/ReactUWP/UwpPreparedScriptStore.h | 25 ++--- 3 files changed, 60 insertions(+), 81 deletions(-) diff --git a/vnext/ReactUWP/Utils/LocalBundleReader.h b/vnext/ReactUWP/Utils/LocalBundleReader.h index 2660e6c64f3..e2ebbece597 100644 --- a/vnext/ReactUWP/Utils/LocalBundleReader.h +++ b/vnext/ReactUWP/Utils/LocalBundleReader.h @@ -5,7 +5,6 @@ #include #include #include -#include namespace react { namespace uwp { diff --git a/vnext/ReactUWP/UwpPreparedScriptStore.cpp b/vnext/ReactUWP/UwpPreparedScriptStore.cpp index 189699da31e..d3e81df9bf2 100644 --- a/vnext/ReactUWP/UwpPreparedScriptStore.cpp +++ b/vnext/ReactUWP/UwpPreparedScriptStore.cpp @@ -13,18 +13,17 @@ #pragma optimize( "", off ) #endif -using namespace winrt::Windows; +namespace winrt { + using namespace winrt::Windows::Foundation; + using namespace winrt::Windows::Storage; +}; namespace react { namespace uwp { UwpPreparedScriptStore::UwpPreparedScriptStore(winrt::hstring uri) { if (!uri.empty()) { - auto file = Storage::ApplicationData::Current().LocalFolder().TryGetItemAsync(uri).get(); - if (file) - { - m_byteCodeFileUri = uri; - } + m_byteCodeFileAsync = winrt::StorageFile::GetFileFromApplicationUriAsync(winrt::Uri(uri)); } } @@ -34,19 +33,27 @@ std::unique_ptr UwpPreparedScriptStore::tryGetPrepa const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. ) noexcept { - // check if app bundle version is older than or equal to the prepared script version - // if true then just read the buffer from the prepared script and return - if (shouldGetPreparedScript(scriptSignature.version)) - { - auto buffer = ByteCodeManager::ReadByteCodeFileAsync(m_byteCodeFileUri).get(); + try { + // check if app bundle version is older than or equal to the prepared script version + // if true then just read the buffer from the prepared script and return + + + auto byteCodeFile = TryGetByteCodeFileSync(scriptSignature.version); + if (byteCodeFile == nullptr) { + return nullptr; + } + + auto buffer = winrt::FileIO::ReadBufferAsync(byteCodeFile).get(); auto bytecodeBuffer(std::make_unique(buffer.Length())); - auto dataReader{ Storage::Streams::DataReader::FromBuffer(buffer) }; + auto dataReader{ winrt::Streams::DataReader::FromBuffer(buffer) }; dataReader.ReadBytes(winrt::array_view { &bytecodeBuffer->data()[0], &bytecodeBuffer->data()[bytecodeBuffer->size()] }); dataReader.Close(); return bytecodeBuffer; } - return nullptr; + catch (...) { + return nullptr; + } } void UwpPreparedScriptStore::persistPreparedScript( @@ -56,67 +63,49 @@ void UwpPreparedScriptStore::persistPreparedScript( const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. ) noexcept { - // generate a new bytecode file - ByteCodeManager::CreateByteCodeFileAsync(preparedScript); + persistPreparedScriptAsync(preparedScript, scriptMetadata, runtimeMetadata, prepareTag); } -bool UwpPreparedScriptStore::shouldGetPreparedScript(facebook::jsi::ScriptVersion_t version) noexcept +winrt::fire_and_forget UwpPreparedScriptStore::persistPreparedScriptAsync( + std::shared_ptr preparedScript, + const facebook::jsi::ScriptSignature& scriptMetadata, + const facebook::jsi::JSRuntimeSignature& runtimeMetadata, + const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. +) { - auto createdDateTime = ByteCodeManager::GetByteCodeFileCreatedDateAsync(m_byteCodeFileUri).get(); - std::uint64_t timestamp = createdDateTime.time_since_epoch().count(); - - // try using default bytecode file url if given url is older than app bundle - if (timestamp < version && !m_byteCodeFileUri.empty()) - { - m_byteCodeFileUri = nullptr; - return shouldGetPreparedScript(version); + try { + co_await winrt::resume_background(); + auto folder = winrt::ApplicationData::Current().LocalCacheFolder(); + auto file = co_await folder.CreateFileAsync(L"app.bytecode", winrt::CreationCollisionOption::ReplaceExisting); + winrt::FileIO::WriteBytesAsync(file, winrt::array_view{ &preparedScript->data()[0], &preparedScript->data()[preparedScript->size()] }); + } + catch (...) { } - - return timestamp >= version; } -std::future ByteCodeManager::GetByteCodeFileCreatedDateAsync(winrt::hstring fileName) +winrt::StorageFile UwpPreparedScriptStore::TryGetByteCodeFileSync(facebook::jsi::ScriptVersion_t version) { - co_await winrt::resume_background(); - - try - { - auto file = fileName.empty() ? - co_await Storage::ApplicationData::Current().LocalCacheFolder().GetFileAsync(L"app.bytecode") : - co_await Storage::StorageFile::GetFileFromApplicationUriAsync(Foundation::Uri(fileName)); - return file.DateCreated(); + try { + if (m_byteCodeFileAsync != nullptr) { + auto file = m_byteCodeFileAsync.get(); + auto createdDateTime = file.DateCreated(); + facebook::jsi::ScriptVersion_t byteCodeVersion = createdDateTime.time_since_epoch().count(); + if (byteCodeVersion >= version) { + return file; + } + } } - catch (winrt::hresult_error const& ex) - { - Foundation::DateTime date; - return date; + catch (...) { + // Eat this exception. If we can't get the file from the uri. Still try looking in the cache. } -} -winrt::fire_and_forget ByteCodeManager::CreateByteCodeFileAsync(std::shared_ptr preparedScript) -{ - auto folder = Storage::ApplicationData::Current().LocalCacheFolder(); - co_await winrt::resume_background(); - auto file = co_await folder.CreateFileAsync(L"app.bytecode", Storage::CreationCollisionOption::ReplaceExisting); - Storage::FileIO::WriteBytesAsync(file, winrt::array_view{ &preparedScript->data()[0], &preparedScript->data()[preparedScript->size()] }); -} + // Getting here means one of two things. No bytecode file uri was specified, or the file uri was specified but it is outdated. + // Try looking in LocalCache folder for app.bytecode and use that. + auto file = winrt::ApplicationData::Current().LocalCacheFolder().GetFileAsync(L"app.bytecode").get(); + auto createdDateTime = file.DateCreated(); + facebook::jsi::ScriptVersion_t byteCodeVersion = createdDateTime.time_since_epoch().count(); -std::future ByteCodeManager::ReadByteCodeFileAsync(winrt::hstring fileName) -{ - co_await winrt::resume_background(); - try - { - auto file = fileName.empty() ? - co_await Storage::ApplicationData::Current().LocalCacheFolder().GetFileAsync(L"app.bytecode") : - co_await Storage::StorageFile::GetFileFromApplicationUriAsync(Foundation::Uri(fileName)); - auto buffer = co_await Storage::FileIO::ReadBufferAsync(file); - return buffer; - } - catch (winrt::hresult_error const& ex) - { - return nullptr; - } + return byteCodeVersion > version ? file : nullptr; } - }} diff --git a/vnext/ReactUWP/UwpPreparedScriptStore.h b/vnext/ReactUWP/UwpPreparedScriptStore.h index 4c03a962f2a..2dfc882baed 100644 --- a/vnext/ReactUWP/UwpPreparedScriptStore.h +++ b/vnext/ReactUWP/UwpPreparedScriptStore.h @@ -8,7 +8,6 @@ #include "jsi/jsi.h" namespace react { namespace uwp { - class UwpPreparedScriptStore : public facebook::jsi::PreparedScriptStore { public: @@ -26,21 +25,13 @@ class UwpPreparedScriptStore : public facebook::jsi::PreparedScriptStore const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. ) noexcept override; private: - bool shouldGetPreparedScript(facebook::jsi::ScriptVersion_t v) noexcept; - winrt::hstring m_byteCodeFileUri; -}; - -class ByteCodeManager -{ -public: - // Get byte code file created date to compare with app bundle file created date - static std::future GetByteCodeFileCreatedDateAsync(winrt::hstring fileName); - - // Create byte code file to re-use when app bundle did not change - static winrt::fire_and_forget CreateByteCodeFileAsync(std::shared_ptr preparedScript); - - // Read from byte code file - static std::future ReadByteCodeFileAsync(winrt::hstring fileName); + winrt::fire_and_forget persistPreparedScriptAsync( + std::shared_ptr preparedScript, + const facebook::jsi::ScriptSignature& scriptMetadata, + const facebook::jsi::JSRuntimeSignature& runtimeMetadata, + const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. + ) noexcept; + winrt::Windows::Storage::StorageFile TryGetByteCodeFileSync(facebook::jsi::ScriptVersion_t version); + winrt::Windows::Foundation::IAsyncOperation m_byteCodeFileAsync; }; - }} From 49aae2fc3c1cd77e9cdb66febdbe7c67d793feda Mon Sep 17 00:00:00 2001 From: Stephen Crain Date: Thu, 20 Jun 2019 10:17:59 -0700 Subject: [PATCH 10/13] use modified date not created --- vnext/ReactUWP/UwpPreparedScriptStore.cpp | 19 +++++++----------- vnext/ReactUWP/UwpPreparedScriptStore.h | 24 ++++++++++++++++++++++- vnext/ReactUWP/UwpScriptStore.cpp | 22 +++++++++++++-------- vnext/ReactUWP/UwpScriptStore.h | 2 +- 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/vnext/ReactUWP/UwpPreparedScriptStore.cpp b/vnext/ReactUWP/UwpPreparedScriptStore.cpp index d3e81df9bf2..856970e70b6 100644 --- a/vnext/ReactUWP/UwpPreparedScriptStore.cpp +++ b/vnext/ReactUWP/UwpPreparedScriptStore.cpp @@ -1,10 +1,7 @@ #include "pch.h" #include "UwpPreparedScriptStore.h" -#include -#include -#include -#include "ChakraJsiRuntime.h" #include +#include #include "unicode.h" #include "jsi/jsi.h" @@ -34,17 +31,16 @@ std::unique_ptr UwpPreparedScriptStore::tryGetPrepa ) noexcept { try { + // check if app bundle version is older than or equal to the prepared script version // if true then just read the buffer from the prepared script and return - - auto byteCodeFile = TryGetByteCodeFileSync(scriptSignature.version); if (byteCodeFile == nullptr) { return nullptr; } auto buffer = winrt::FileIO::ReadBufferAsync(byteCodeFile).get(); - auto bytecodeBuffer(std::make_unique(buffer.Length())); + auto bytecodeBuffer(std::make_unique(buffer.Length())); auto dataReader{ winrt::Streams::DataReader::FromBuffer(buffer) }; dataReader.ReadBytes(winrt::array_view { &bytecodeBuffer->data()[0], &bytecodeBuffer->data()[bytecodeBuffer->size()] }); dataReader.Close(); @@ -88,8 +84,8 @@ winrt::StorageFile UwpPreparedScriptStore::TryGetByteCodeFileSync(facebook::jsi: try { if (m_byteCodeFileAsync != nullptr) { auto file = m_byteCodeFileAsync.get(); - auto createdDateTime = file.DateCreated(); - facebook::jsi::ScriptVersion_t byteCodeVersion = createdDateTime.time_since_epoch().count(); + auto fileprops = file.GetBasicPropertiesAsync().get(); + facebook::jsi::ScriptVersion_t byteCodeVersion = fileprops.DateModified().time_since_epoch().count(); if (byteCodeVersion >= version) { return file; } @@ -99,12 +95,11 @@ winrt::StorageFile UwpPreparedScriptStore::TryGetByteCodeFileSync(facebook::jsi: // Eat this exception. If we can't get the file from the uri. Still try looking in the cache. } - // Getting here means one of two things. No bytecode file uri was specified, or the file uri was specified but it is outdated. // Try looking in LocalCache folder for app.bytecode and use that. auto file = winrt::ApplicationData::Current().LocalCacheFolder().GetFileAsync(L"app.bytecode").get(); - auto createdDateTime = file.DateCreated(); - facebook::jsi::ScriptVersion_t byteCodeVersion = createdDateTime.time_since_epoch().count(); + auto fileprops = file.GetBasicPropertiesAsync().get(); + facebook::jsi::ScriptVersion_t byteCodeVersion = fileprops.DateModified().time_since_epoch().count(); return byteCodeVersion > version ? file : nullptr; } diff --git a/vnext/ReactUWP/UwpPreparedScriptStore.h b/vnext/ReactUWP/UwpPreparedScriptStore.h index 2dfc882baed..6fa399a7dc0 100644 --- a/vnext/ReactUWP/UwpPreparedScriptStore.h +++ b/vnext/ReactUWP/UwpPreparedScriptStore.h @@ -30,8 +30,30 @@ class UwpPreparedScriptStore : public facebook::jsi::PreparedScriptStore const facebook::jsi::ScriptSignature& scriptMetadata, const facebook::jsi::JSRuntimeSignature& runtimeMetadata, const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. - ) noexcept; + ); winrt::Windows::Storage::StorageFile TryGetByteCodeFileSync(facebook::jsi::ScriptVersion_t version); winrt::Windows::Foundation::IAsyncOperation m_byteCodeFileAsync; }; + +// This is very similiar to ByteArrayBuffer in ChakraJsiRuntime.h. +// Defining this to avoid referencing types in chakra headers +class ByteCodeBuffer final : public facebook::jsi::Buffer { +public: + size_t size() const override { + return size_; + } + const uint8_t* data() const { + return byteArray_.get(); + } + + uint8_t* data() { + return byteArray_.get(); + } + + ByteCodeBuffer(int size) : size_(size), byteArray_(std::make_unique(size)) {} + +private: + int size_; + std::unique_ptr byteArray_; +}; }} diff --git a/vnext/ReactUWP/UwpScriptStore.cpp b/vnext/ReactUWP/UwpScriptStore.cpp index 18dd83a7e39..5065872651a 100644 --- a/vnext/ReactUWP/UwpScriptStore.cpp +++ b/vnext/ReactUWP/UwpScriptStore.cpp @@ -1,9 +1,16 @@ #include "pch.h" #include "UwpScriptStore.h" #include +#include +#include #include #include "unicode.h" +namespace winrt { + using namespace winrt::Windows::Foundation; + using namespace winrt::Windows::Storage; +} + namespace react { namespace uwp { facebook::jsi::VersionedBuffer UwpScriptStore::getVersionedScript(const std::string& url) noexcept @@ -19,26 +26,25 @@ facebook::jsi::VersionedBuffer UwpScriptStore::getVersionedScript(const std::str facebook::jsi::ScriptVersion_t UwpScriptStore::getScriptVersion(const std::string& url) noexcept { const std::string bundleUrl = "ms-appx:///Bundle/" + url + ".bundle"; - const winrt::Windows::Foundation::DateTime bundleCreatedTime = getBundleCreatedDate(bundleUrl).get(); - const std::uint64_t timestamp = bundleCreatedTime.time_since_epoch().count(); + const winrt::DateTime bundleModifiedTime = getBundleModifiedDate(bundleUrl).get(); + const std::uint64_t timestamp = bundleModifiedTime.time_since_epoch().count(); return timestamp; } -std::future UwpScriptStore::getBundleCreatedDate(const std::string& bundleUri) +std::future UwpScriptStore::getBundleModifiedDate(const std::string& bundleUri) { winrt::hstring str(facebook::react::unicode::utf8ToUtf16(bundleUri)); winrt::Windows::Foundation::Uri uri(str); - co_await winrt::resume_background(); - try { - auto file = co_await winrt::Windows::Storage::StorageFile::GetFileFromApplicationUriAsync(uri); - return file.DateCreated(); + auto file = co_await winrt::StorageFile::GetFileFromApplicationUriAsync(uri); + auto props = file.GetBasicPropertiesAsync().get(); + return props.DateModified(); } catch (winrt::hresult_error const& ex) { - winrt::Windows::Foundation::DateTime date; + winrt::DateTime date; return date; } } diff --git a/vnext/ReactUWP/UwpScriptStore.h b/vnext/ReactUWP/UwpScriptStore.h index 7937f393342..22b50fa10f1 100644 --- a/vnext/ReactUWP/UwpScriptStore.h +++ b/vnext/ReactUWP/UwpScriptStore.h @@ -10,7 +10,7 @@ class UwpScriptStore : public facebook::jsi::ScriptStore facebook::jsi::VersionedBuffer getVersionedScript(const std::string& url) noexcept override; facebook::jsi::ScriptVersion_t getScriptVersion(const std::string& url) noexcept override; private: - std::future getBundleCreatedDate(const std::string& bundlePath); + std::future getBundleModifiedDate(const std::string& bundlePath); }; }} From 43ffb07cb858f6274cbcea180282aeb603be6d5a Mon Sep 17 00:00:00 2001 From: Joseph Bui Date: Thu, 20 Jun 2019 14:21:04 -0700 Subject: [PATCH 11/13] excluded stores from OSS_RN, hide copy constructors/assignments, used source url in naming of bytecode file --- vnext/ReactUWP/ReactUWP.vcxproj | 8 ++++---- vnext/ReactUWP/UwpPreparedScriptStore.cpp | 16 +++++++++------- vnext/ReactUWP/UwpPreparedScriptStore.h | 7 ++++++- vnext/ReactUWP/UwpScriptStore.cpp | 2 ++ vnext/ReactUWP/UwpScriptStore.h | 3 +++ 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/vnext/ReactUWP/ReactUWP.vcxproj b/vnext/ReactUWP/ReactUWP.vcxproj index a86c8ab5412..94007881fe3 100644 --- a/vnext/ReactUWP/ReactUWP.vcxproj +++ b/vnext/ReactUWP/ReactUWP.vcxproj @@ -167,8 +167,8 @@ - - + + @@ -252,8 +252,8 @@ - - + + diff --git a/vnext/ReactUWP/UwpPreparedScriptStore.cpp b/vnext/ReactUWP/UwpPreparedScriptStore.cpp index 856970e70b6..023951cef39 100644 --- a/vnext/ReactUWP/UwpPreparedScriptStore.cpp +++ b/vnext/ReactUWP/UwpPreparedScriptStore.cpp @@ -34,7 +34,7 @@ std::unique_ptr UwpPreparedScriptStore::tryGetPrepa // check if app bundle version is older than or equal to the prepared script version // if true then just read the buffer from the prepared script and return - auto byteCodeFile = TryGetByteCodeFileSync(scriptSignature.version); + auto byteCodeFile = TryGetByteCodeFileSync(scriptSignature); if (byteCodeFile == nullptr) { return nullptr; } @@ -72,21 +72,22 @@ winrt::fire_and_forget UwpPreparedScriptStore::persistPreparedScriptAsync( try { co_await winrt::resume_background(); auto folder = winrt::ApplicationData::Current().LocalCacheFolder(); - auto file = co_await folder.CreateFileAsync(L"app.bytecode", winrt::CreationCollisionOption::ReplaceExisting); + auto fileName = winrt::to_hstring(scriptMetadata.url + ".bytecode"); + auto file = co_await folder.CreateFileAsync(fileName, winrt::CreationCollisionOption::ReplaceExisting); winrt::FileIO::WriteBytesAsync(file, winrt::array_view{ &preparedScript->data()[0], &preparedScript->data()[preparedScript->size()] }); } catch (...) { } } -winrt::StorageFile UwpPreparedScriptStore::TryGetByteCodeFileSync(facebook::jsi::ScriptVersion_t version) +winrt::StorageFile UwpPreparedScriptStore::TryGetByteCodeFileSync(const facebook::jsi::ScriptSignature& scriptSignature) { try { if (m_byteCodeFileAsync != nullptr) { auto file = m_byteCodeFileAsync.get(); auto fileprops = file.GetBasicPropertiesAsync().get(); facebook::jsi::ScriptVersion_t byteCodeVersion = fileprops.DateModified().time_since_epoch().count(); - if (byteCodeVersion >= version) { + if (byteCodeVersion >= scriptSignature.version) { return file; } } @@ -96,11 +97,12 @@ winrt::StorageFile UwpPreparedScriptStore::TryGetByteCodeFileSync(facebook::jsi: } // Getting here means one of two things. No bytecode file uri was specified, or the file uri was specified but it is outdated. - // Try looking in LocalCache folder for app.bytecode and use that. - auto file = winrt::ApplicationData::Current().LocalCacheFolder().GetFileAsync(L"app.bytecode").get(); + // Try looking in LocalCache folder for bytecode file and use that. + auto fileName = winrt::to_hstring(scriptSignature.url + ".bytecode"); + auto file = winrt::ApplicationData::Current().LocalCacheFolder().GetFileAsync(fileName).get(); auto fileprops = file.GetBasicPropertiesAsync().get(); facebook::jsi::ScriptVersion_t byteCodeVersion = fileprops.DateModified().time_since_epoch().count(); - return byteCodeVersion > version ? file : nullptr; + return byteCodeVersion > scriptSignature.version ? file : nullptr; } }} diff --git a/vnext/ReactUWP/UwpPreparedScriptStore.h b/vnext/ReactUWP/UwpPreparedScriptStore.h index 6fa399a7dc0..acab5ac9873 100644 --- a/vnext/ReactUWP/UwpPreparedScriptStore.h +++ b/vnext/ReactUWP/UwpPreparedScriptStore.h @@ -24,6 +24,9 @@ class UwpPreparedScriptStore : public facebook::jsi::PreparedScriptStore const facebook::jsi::JSRuntimeSignature& runtimeMetadata, const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. ) noexcept override; + + UwpPreparedScriptStore(const UwpPreparedScriptStore&) = delete; + void operator=(const UwpPreparedScriptStore&) = delete; private: winrt::fire_and_forget persistPreparedScriptAsync( std::shared_ptr preparedScript, @@ -31,7 +34,7 @@ class UwpPreparedScriptStore : public facebook::jsi::PreparedScriptStore const facebook::jsi::JSRuntimeSignature& runtimeMetadata, const char* prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache. ); - winrt::Windows::Storage::StorageFile TryGetByteCodeFileSync(facebook::jsi::ScriptVersion_t version); + winrt::Windows::Storage::StorageFile TryGetByteCodeFileSync(const facebook::jsi::ScriptSignature& scriptSignature); winrt::Windows::Foundation::IAsyncOperation m_byteCodeFileAsync; }; @@ -51,6 +54,8 @@ class ByteCodeBuffer final : public facebook::jsi::Buffer { } ByteCodeBuffer(int size) : size_(size), byteArray_(std::make_unique(size)) {} + ByteCodeBuffer(const ByteCodeBuffer&) = delete; + void operator=(const ByteCodeBuffer&) = delete; private: int size_; diff --git a/vnext/ReactUWP/UwpScriptStore.cpp b/vnext/ReactUWP/UwpScriptStore.cpp index 5065872651a..1dfa81017ee 100644 --- a/vnext/ReactUWP/UwpScriptStore.cpp +++ b/vnext/ReactUWP/UwpScriptStore.cpp @@ -13,6 +13,8 @@ namespace winrt { namespace react { namespace uwp { +UwpScriptStore::UwpScriptStore() {} + facebook::jsi::VersionedBuffer UwpScriptStore::getVersionedScript(const std::string& url) noexcept { facebook::jsi::VersionedBuffer versionedBuffer_; diff --git a/vnext/ReactUWP/UwpScriptStore.h b/vnext/ReactUWP/UwpScriptStore.h index 22b50fa10f1..b30d627cf13 100644 --- a/vnext/ReactUWP/UwpScriptStore.h +++ b/vnext/ReactUWP/UwpScriptStore.h @@ -9,6 +9,9 @@ class UwpScriptStore : public facebook::jsi::ScriptStore public: facebook::jsi::VersionedBuffer getVersionedScript(const std::string& url) noexcept override; facebook::jsi::ScriptVersion_t getScriptVersion(const std::string& url) noexcept override; + UwpScriptStore(); + UwpScriptStore(const UwpScriptStore&) = delete; + void operator=(const UwpScriptStore&) = delete; private: std::future getBundleModifiedDate(const std::string& bundlePath); }; From cee3723c0de52b9237c2bba710fc9b51655422e0 Mon Sep 17 00:00:00 2001 From: Joseph Bui Date: Thu, 20 Jun 2019 15:13:40 -0700 Subject: [PATCH 12/13] excluded OSS_RN from uwpreactinstance --- vnext/ReactUWP/ReactUWP.vcxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vnext/ReactUWP/ReactUWP.vcxproj b/vnext/ReactUWP/ReactUWP.vcxproj index 94007881fe3..ca84ef1451b 100644 --- a/vnext/ReactUWP/ReactUWP.vcxproj +++ b/vnext/ReactUWP/ReactUWP.vcxproj @@ -166,7 +166,7 @@ - + @@ -251,7 +251,7 @@ - + From 72fc234325b73127c0727a0a40783e05327cd8ef Mon Sep 17 00:00:00 2001 From: Joseph Bui Date: Thu, 20 Jun 2019 15:19:04 -0700 Subject: [PATCH 13/13] fix OSS_RN exclude placement for uwpreactinstance --- vnext/ReactUWP/Base/UwpReactInstance.cpp | 2 ++ vnext/ReactUWP/ReactUWP.vcxproj | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/vnext/ReactUWP/Base/UwpReactInstance.cpp b/vnext/ReactUWP/Base/UwpReactInstance.cpp index 3422b14cad1..63726e9da4e 100644 --- a/vnext/ReactUWP/Base/UwpReactInstance.cpp +++ b/vnext/ReactUWP/Base/UwpReactInstance.cpp @@ -64,8 +64,10 @@ #include #include +#if !defined(OSS_RN) #include #include +#endif #if !defined(OSS_RN) #include "ChakraJSIRuntimeHolder.h" diff --git a/vnext/ReactUWP/ReactUWP.vcxproj b/vnext/ReactUWP/ReactUWP.vcxproj index ca84ef1451b..94007881fe3 100644 --- a/vnext/ReactUWP/ReactUWP.vcxproj +++ b/vnext/ReactUWP/ReactUWP.vcxproj @@ -166,7 +166,7 @@ - + @@ -251,7 +251,7 @@ - +