More Engine optimization

This commit is contained in:
DepressedTWM 2026-08-19 11:18:23 +04:00
parent 1f48ab469f
commit 94134c1ea6
5 changed files with 118 additions and 84 deletions

View file

@ -380,7 +380,8 @@ else()
-fipa-pta -fipa-pta
-fext-dce -fext-dce
-fstrict-enums -fstrict-enums
-fimplicit-constexpr) -fimplicit-constexpr
-fomit-frame-pointer)
add_compile_options(${OPTIONS_RELEASE}) add_compile_options(${OPTIONS_RELEASE})
add_link_options(-Wl,-O2 add_link_options(-Wl,-O2

View file

@ -1,71 +1,113 @@
# Engine benchmark idk, check speed via linux time utility N = 5_000_000
begin sink = 0
RPG::Mod.exec_hooks("test", binding)
count = 0
while count <= 500000 do
puts count
count += 1
end
while count >= 1 do
puts count
count -= 1
end
count = 1.5 # 1. Цикл, арифметика и ветвления
while count <= 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 do i = 0
puts count while i < N
count = count * count sink ^= (i * 31 + 17) % 1_000_003
end i += 1
count = 2
while count <= 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 do
puts count
count = count * count
end
count = 1
while count <= 5000 do
Graphics.frame_rate = count
count += 1
end
count = 1
while count <= 60 do
Font.default_size = count
count += 1
end
Sunshine.crashprivacy=true
Wallpaper.reset
Input.set_led(255, 150, 30)
Graphics.freeze
Wallpaper.reset
File.exist?("oneshot")
Oneshot.exiting false
Oneshot.exiting true
puts CTime.month
puts CTime.day
puts CTime.hour
puts Sunshine::SDLVersion_major
puts Sunshine::SECURITYSTATE
puts Sunshine::DEVBUILD
count = 0
while count <= 999999 do
count.clone
count = count + 1
puts count
Graphics.update
begin
raise 'Boom!'
rescue
puts 'Rescued an exception.'
end
begin
1 / 0 # Raises ZeroDivisionError, a subclass of StandardError.
rescue
puts "Rescued #{$!.class}"
end
end
rescue Errno::ENOENT
filename = $!.message.sub("No such file or directory - ", "")
print("Unable to find file #{filename}.")
end end
# 2. Вызовы методов
class TestObject
def initialize(value)
@value = value
end
def calculate(x)
((@value + x) * 3) ^ 0x55aa
end
end
objects = Array.new(10) { |x| TestObject.new(x) }
i = 0
while i < N
sink ^= objects[i % objects.length].calculate(i)
i += 1
end
# 3. Создание объектов и сборка мусора
i = 0
while i < N
data = {
id: i,
name: "object_#{i}",
values: [i, i * 2, i * 3],
enabled: (i & 1) == 0
}
sink ^= data[:values][1]
i += 1
end
# 4. Строковые операции
text = "benchmark_string_" * 20
i = 0
while i < N
value = "#{text}:#{i}".upcase.reverse
sink ^= value.length
i += 1
end
# 5. Массивы
array = Array.new(10_000) { |x| x }
i = 0
while i < N
array[i % array.length] = (array[i % array.length] * 31 + i) % 1_000_003
sink ^= array[i % array.length]
i += 1
end
# 6. Hash lookup
hash = {}
10_000.times do |x|
hash["key_#{x}"] = x
end
i = 0
while i < N
sink ^= hash["key_#{i % 10_000}"]
i += 1
end
# 7. BigInt-арифметика
big = (1 << 100_000) + 12_345
200.times do
big = big * big
big %= (1 << 100_000) - 1
sink ^= big & 0xffff
end
# 8. Исключения
exception_count = 100_000
i = 0
while i < exception_count
begin
raise RuntimeError, "benchmark error"
rescue RuntimeError
sink += 1
end
i += 1
end
# 9. clone / dup
object = {
name: "test",
values: Array.new(100, 123),
nested: { enabled: true }
}
i = 0
while i < N
copy = object.dup
sink ^= copy[:values].length
i += 1
end
puts "sink=#{sink}"

View file

@ -26,7 +26,6 @@
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include <ruby.h> #include <ruby.h>
#include <source_location>
#include "meow.h" #include "meow.h"
#undef vsnprintf #undef vsnprintf
#undef snprintf #undef snprintf
@ -39,7 +38,7 @@
class Debug{ class Debug{
public: public:
explicit Debug(const std::source_location location = std::source_location::current()) : location(location){ explicit Debug(){
buf << std::boolalpha; buf << std::boolalpha;
} }
@ -65,22 +64,19 @@ public:
return *this; return *this;
} }
~Debug(){ ~Debug() noexcept {
std::ostringstream result;
result << "[" << location.line() << ":" << location.function_name() << "] " << buf.view();
#ifdef __ANDROID__ #ifdef __ANDROID__
__android_log_write(ANDROID_LOG_DEBUG, "sunshine", result.view().c_str()); __android_log_write(ANDROID_LOG_DEBUG, "sunshine", result.view().c_str());
#elif __EMSCRIPTEN__ #elif __EMSCRIPTEN__
emscripten_console_log(result.view().c_str()); emscripten_console_log(result.view().c_str());
#else #else
logs.emplace_back(result.view()); logs.emplace_back(buf.view());
std::cout << std::move(result).str() << '\n'; std::cout << buf.view() << '\n';
#endif #endif
} }
private: private:
std::ostringstream buf; std::ostringstream buf;
std::source_location location;
}; };
#endif // DEBUGWRITER_H #endif // DEBUGWRITER_H

View file

@ -1,5 +1,4 @@
#include <SDL3/SDL_platform_defines.h> #include <SDL3/SDL_platform_defines.h>
#if defined(SDL_PLATFORM_AIX) || defined(SDL_PLATFORM_BSDI) || defined(SDL_PLATFORM_FREEBSD) || \ #if defined(SDL_PLATFORM_AIX) || defined(SDL_PLATFORM_BSDI) || defined(SDL_PLATFORM_FREEBSD) || \
defined(SDL_PLATFORM_HPUX) || defined(SDL_PLATFORM_HURD) || defined(SDL_PLATFORM_IRIX) || \ defined(SDL_PLATFORM_HPUX) || defined(SDL_PLATFORM_HURD) || defined(SDL_PLATFORM_IRIX) || \
defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_NETBSD) || \ defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_MACOS) || defined(SDL_PLATFORM_NETBSD) || \
@ -44,10 +43,6 @@
#define os2 1 #define os2 1
#endif #endif
#if SDL_PLATFORM_PS2
#define ps2 1
#endif
#if SDL_PLATFORM_PSP #if SDL_PLATFORM_PSP
#define psp 1 #define psp 1
#endif #endif

View file

@ -18,7 +18,6 @@
** You should have received a copy of the GNU General Public License ** You should have received a copy of the GNU General Public License
** along with mkxp. If not, see <http://www.gnu.org/licenses/>. ** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <SDL3_image/SDL_image.h> #include <SDL3_image/SDL_image.h>
#include <SDL3_ttf/SDL_ttf.h> #include <SDL3_ttf/SDL_ttf.h>
@ -337,10 +336,11 @@ int main(int argc, char *argv[]){
/* If RGSS thread ack'd request, wait for it to shutdown, /* If RGSS thread ack'd request, wait for it to shutdown,
* otherwise abandon hope and just end the process as is. */ * otherwise abandon hope and just end the process as is. */
if (rtData.rqTermAck) if (rtData.rqTermAck){
SDL_WaitThread(rgssThread, 0); SDL_WaitThread(rgssThread, 0);
else }else{
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, conf.windowTitle.c_str(), "The RGSS script seems to be stuck and Sunshine will now force quit", win); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, conf.windowTitle.c_str(), "The RGSS script seems to be stuck and Sunshine will now force quit", win);
}
if (!rtData.rgssErrorMsg.empty()) if (!rtData.rgssErrorMsg.empty())
ErrorMsg(rtData.rgssErrorMsg.c_str()); ErrorMsg(rtData.rgssErrorMsg.c_str());