FFM (Foreign Function and Memory) Stdlib Example

FFM is the new API trying to replace JNI and jep is here It is basically calling functions outside of JVM or accessing memory not managed by JVM. I wanted to test can FFM beat regular Java API, below you can find a simple test doing math sin with FFM and with regular Math.sin import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.Linker; import java.lang.foreign.MemorySegment; import java.lang.foreign.SymbolLookup; import java.lang.foreign.ValueLayout; public class FFMSinTest { public static void main(String[] args) throws Throwable { Linker linker = Linker.nativeLinker(); SymbolLookup stdlib = linker.defaultLookup(); // Locate the "sin" function in the C math library MemorySegment sinAddress = stdlib.find("sin").orElseThrow(); FunctionDescriptor descriptor = FunctionDescriptor.of(ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE); var sinHandle = linker.downcallHandle(sinAddress, descriptor); double angle = Math.PI / 4; // 45 degrees in radians // Timing Java's Math.sin() long javaStartTime = System.nanoTime(); for (int i = 0; i < 1_000_000; i++) { double result = Math.sin(angle); } long javaEndTime = System.nanoTime(); long javaDuration = javaEndTime - javaStartTime; // Timing C sin via FFM long ffmStartTime = System.nanoTime(); for (int i = 0; i < 1_000_000; i++) { double result = (double) sinHandle.invoke(angle); } long ffmEndTime = System.nanoTime(); long ffmDuration = ffmEndTime - ffmStartTime; System.out.println("Java Math.sin() took: " + javaDuration / 1_000_000.0 + " ms"); System.out.println("C sin (FFM) took: " + ffmDuration / 1_000_000.0 + " ms"); } } And result is ...

November 11, 2024 · 2 min · Özkan Pakdil

How to disable win11 startmenu internet search

Whenever I search anything on the start menu it triggers an internet search at the back and brings some results and suggestions from web, I use browser to do internet things, when we start mixing that to regular windows programs that slows down the computer, and I do not like slow windows. Below you can find a way to disable that online search. @echo off :: Check if running as administrator net session >nul 2>&1 if %errorLevel% NEQ 0 ( echo Requesting administrator privileges... powershell -Command "Start-Process '%0' -Verb RunAs" exit /b ) REM Disable Search the Web in Windows 11 REM Create the registry key if it doesn't exist reg add "HKCU\Software\Policies\Microsoft\Windows\Explorer" /f REM Set DisableSearchBoxSuggestions to 1 reg add "HKCU\Software\Policies\Microsoft\Windows\Explorer" /v DisableSearchBoxSuggestions /t REG_DWORD /d 1 /f echo "Search the Web in Windows 11 has been disabled. Please sign out and sign back in to apply changes." pause Put this script into any .bat file and run it in windows11 and logoff login or restart your machine and start menu works faster after that. It still search in the computer that maybe disabled too but that is for another blog post. ...

November 7, 2024 · 1 min · Özkan Pakdil

How to Use Lunr.js for Searching in a Jekyll Blog

I have been using Google Programmable Search Engine on my blog, but I found that it doesn’t work quite as I expected. First, I tried Bing and DuckDuckGo as alternatives, but none of them performed as desired. DuckDuckGo’s API is nice, but it lacks a ‘site:’ filter, which prevented it from working as needed. Here are the steps to set up a Jekyll search system using Lunr.js for GitHub Pages(github.io): Create js/search.js and add this code Add search.md to the root of your project. Add an HTML form where you like <li class="nav-item my-auto"> <div class="header-search"> <form class="header-search-form" action="/search.html" method="get"> <input type="text" id="search-box" name="query"> <input type="submit" value="search"> </form> </div> </li> Check here for example. ...

November 5, 2024 · 1 min · Özkan Pakdil

Graalvm to run wasm from spring boot

Graalvm is AOT compilation advanced JDK, I am following the project since 2019, Project’s first target was AOT now lately I start seeing more about multi language support. It supports Python, JS, Ruby, Wasm more details here And WASM is getting popular day by day, WASM is a new binary file for web. There are many cool examples of WASM Doom game in the browser with graalvm Postgres database in the browser I was wondering how to run WASM code in simple spring boot application, ...

November 4, 2024 · 1 min · Özkan Pakdil

Claude ai computer use

Latest AI news are making GPT and others very popular, and this is AI bubble, probably it will settle down in 2-3 years and we will have stable AI. Right now people are scared they will lose their job, some are very excited to try new things and test the fringe. Anyway couple of days ago I heard about claude ai published that computer use feature, basically AI will use our computer to do our prompts. What is that mean ? it means from simple stuff like copy this file from folder 1 to 2 or go research about cats and find me whales in google and categorically create folders of whales for me to look at that in the evening. So AI will do all and wait for you to check. ...

October 29, 2024 · 2 min · Özkan Pakdil