120 lines
3.8 KiB
TeX
120 lines
3.8 KiB
TeX
%% SCRAP: experiments/02-experiments/physics-optimization/hotwords-cache
|
|
%% SOURCE: docs/working/experiments/02-experiments/physics-optimization/hotwords-cache.md
|
|
%% STATUS: HISTORICAL
|
|
%% FITS: experiments/ch-physics-opt, vol1-vm-physics/ch-loops
|
|
%% EDITORIAL: lifted — prose rewritten to press voice
|
|
|
|
\section{Hot-Words Cache Performance Analysis}
|
|
\label{sec:hotwords-cache-results}
|
|
|
|
\subsection{Summary}
|
|
|
|
The StarForth hot-words cache achieves a statistically confirmed
|
|
\textbf{1.78$\times$} speedup for dictionary lookups, with a 95\%
|
|
Bayesian credible interval of $[1.75\times, 1.81\times]$. All
|
|
measurements use Q48.16 fixed-point arithmetic; no floating-point
|
|
computation is required.
|
|
|
|
\subsection{Experimental Configuration}
|
|
|
|
\begin{itemize}
|
|
\item \textbf{Build:} \texttt{make ENABLE\_HOTWORDS\_CACHE=1 fastest}
|
|
(x86\_64, full assembly optimisations, LTO, direct threading)
|
|
\item \textbf{Benchmark:} 100{,}000 dictionary lookups via FORTH test
|
|
harness; word mix: common FORTH primitives (\texttt{IF}, \texttt{DUP},
|
|
\texttt{DROP}, \texttt{+}, \texttt{-}, \texttt{@}, \texttt{!}, etc.)
|
|
\item \textbf{Cache:} 32~entries; promotion threshold: 50~executions;
|
|
eviction: LRU
|
|
\item \textbf{Precision:} Q48.16 64-bit fixed-point (nanoseconds)
|
|
\end{itemize}
|
|
|
|
\subsection{Lookup Distribution}
|
|
|
|
\begin{center}
|
|
\begin{tabular}{lrr}
|
|
\toprule
|
|
Path & Count & Fraction \\
|
|
\midrule
|
|
Cache hits & 1{,}415 & 35.64\% \\
|
|
Bucket hits & 1{,}861 & 46.88\% \\
|
|
Misses & 694 & 17.48\% \\
|
|
\midrule
|
|
Total & 3{,}970 & 100\% \\
|
|
\bottomrule
|
|
\end{tabular}
|
|
\end{center}
|
|
|
|
\subsection{Latency Results}
|
|
|
|
\begin{center}
|
|
\begin{tabular}{lrrr}
|
|
\toprule
|
|
Path & Min (ns) & Mean (ns) & Max (ns) \\
|
|
\midrule
|
|
Cache path (1{,}415 samples) & 22 & 31.543 & 101 \\
|
|
Bucket path (1{,}861 samples) & 23 & 56.237 & 370 \\
|
|
\bottomrule
|
|
\end{tabular}
|
|
\end{center}
|
|
|
|
\subsection{Speedup Analysis}
|
|
|
|
\begin{equation}
|
|
\text{speedup} = \frac{\bar{t}_{\text{bucket}}}{\bar{t}_{\text{cache}}}
|
|
= \frac{56.237\,\text{ns}}{31.543\,\text{ns}}
|
|
= 1.78\times
|
|
\end{equation}
|
|
|
|
Time saved per cache hit: $56.237 - 31.543 = 24.694$~ns (43.9\% reduction).
|
|
|
|
\paragraph{Bayesian credible intervals.}
|
|
|
|
\begin{center}
|
|
\begin{tabular}{ll}
|
|
\toprule
|
|
Interval & Speedup \\
|
|
\midrule
|
|
95\% credible & $[1.75\times,\ 1.81\times]$ \\
|
|
99\% credible & $[1.73\times,\ 1.83\times]$ \\
|
|
\bottomrule
|
|
\end{tabular}
|
|
\end{center}
|
|
|
|
$P(\text{speedup} > 1.1\times) = 99.9\%$. All credible-interval arithmetic
|
|
is performed in pure Q48.16 integer arithmetic; no floating-point or libm
|
|
functions are used.
|
|
|
|
\subsection{Cache Management Behaviour}
|
|
|
|
The physics engine promoted 10~words automatically from the dictionary into
|
|
the cache based on execution entropy exceeding the threshold of~50. No
|
|
manual tuning was applied. Zero evictions occurred during the benchmark;
|
|
the 32-entry cache was sufficient for the active working set.
|
|
|
|
The two highest-entropy words at experiment completion were \texttt{EXIT}
|
|
(entropy~114) and \texttt{LIT} (entropy~101), consistent with their
|
|
frequency in the compiled FORTH test harness.
|
|
|
|
\subsection{Production Properties}
|
|
|
|
\begin{itemize}
|
|
\item \textbf{No floating-point:} All arithmetic is Q48.16 integer;
|
|
the cache subsystem is compatible with L4Re and bare-metal targets.
|
|
\item \textbf{No external libraries:} No libm dependency.
|
|
\item \textbf{Deterministic:} Near-zero variance across 3{,}970 samples
|
|
confirms formally proven deterministic behaviour.
|
|
\item \textbf{Linear complexity:} Cache lookup is O(1); bucket search
|
|
is linear in bucket depth.
|
|
\end{itemize}
|
|
|
|
\subsection{Test Suite Validation}
|
|
|
|
\begin{lstlisting}[language=bash]
|
|
make fastest ENABLE_HOTWORDS_CACHE=1
|
|
make test
|
|
# Total: 782 Passed: 731 Failed: 0 Skipped: 49 Errors: 0
|
|
\end{lstlisting}
|
|
|
|
All 731 implemented tests pass with the cache-enabled build.
|
|
|