I'm trying to make a package for easy font switching for XeTeX. The command that loads such fonts, would automatically try to substitute the missing font (like slanted fonts), and try to guess the font type, and set all the definitions that were defined by default for Computer Modern font. I have an attempt for that, but I clearly remember, that that does not takes too much time to compile.
Now I'm trying to remake with a different approach, that compiling it by it self takes too much time. I'm not certain of the proper use of \newtoks, but I use that to store the name of the font, so whenever I slightly change for instance the font size, I can apply it by only reissue an apply command. Is that possible, that such tokens takes up to ~5-10 second? Or MikTeX have completely wrong setup for XeTeX?
Edit
After some debugging, I figured out, that the slower part is for loading Computer Modern font again. Someone asked me to share the code, however, now that I know where is the problem, I only share the necessary part of the code. (Not that if it would be a secret. I shared a link to the code) Slow part is marked with the text "Ridiculously slow, no matter what".
% Define tokens for fontfaces
\newtoks\rmface
\newtoks\itface
\newtoks\slface
\newtoks\bfface
\newtoks\biface % Bold italic
\newtoks\bsface % Bold slanted
% Technically impossible to create MORE slanted (slanted) italic font, or
% slanted bold slanted italic.
\newtoks\ttface
% I slightly modified the Typewriter Type, so it can be used, with \rm \it etc.
% Although its still be available with \tt.
\newtoks\ttrmface
\newtoks\ttitface
\newtoks\ttslface
\newtoks\ttbfface
\newtoks\ttbiface
\newtoks\ttbsface
\newtoks\titleface
\newtoks\titleitface
\newtoks\titleslface
\newtoks\titlebfface
\newtoks\titlebiface
\newtoks\titlebsface
\newtoks\mrmface % Math roman (for Ms font set)
\newtoks\mitface % Math italic
\newtoks\msyface % Math symbols
\newtoks\mexface % Math extended
\newtoks\calface % Caligraphic face (Restored to default if empty)
\newtoks\setface % Caligraphic face (Removed/Ignored if empty)
\let\omathbb=\relax % Temporary placement of \mathbb, if defined.
[...]
\rmface={cmr10}
\itface={cmr10}
\slface={cmsl10}
\bfface={cmbx10}
\biface={cmbxti10}
\bsface={cmbxsl10}
\titleface={cmss10}
\titleitface={cmssi10}
\titleslface={cmssi10}
\titlebfface={cmssdc10}
\titlebiface={cmssbx10}
\titlebsface={cmssqi8}
\ttface={cmtt10}
\ttrmface={cmtt10}
\ttitface={cmitt10}
\ttslface={cmsltt10}
\ttbfface={cmtt10}
\ttbiface={cmitt10}
\ttbsface={cmsltt10}
\mrmface={cmr10}
\mitface={cmmi10}
\msyface={cmsy10}
\mexface={cmex10}
\calface={}
\setface={}
\fontsize=10pt
\count\footins=830
\titlesize={3}
\hasize={1.5}
\hbsize={1.17}
\hcsize={1.17}
\hdsize={1}
\hesize={1}
\hfsize={.85}
\hgsize={.85}
\hhsize={.85}
\hisize={.85}
[...]
% Defining main font faces
\font\trm="\the\rmface" at \fontsize%
\ifnum\XeTeXfonttype\trm=0\def\oldstyle{\fam1\tit}\else%
\font\osy="\the\rmface:+onum" at \fontsize%
\def\oldstyle{\fam8\osy}\fi%
\if&\the\itface&%
\font\tit="\the\rmface:slant=.2" at \fontsize%
\font\sit="\the\rmface:slant=.2" at .7\fontsize%
\font\fit="\the\rmface:slant=.2" at .5\fontsize%
\else%
\font\tit="\the\itface" at \fontsize%
\font\sit="\the\itface" at .7\fontsize% Ridiculously slow, no matter what.
\font\fit="\the\itface" at .5\fontsize%
\fi%
\if&\the\slface&%
\font\tsl="\the\rmface:slant=.167" at \fontsize%
\font\ssl="\the\rmface:slant=.167" at .7\fontsize%
\font\fsl="\the\rmface:slant=.167" at .5\fontsize%
\else%
\font\tsl="\the\slface" at \fontsize%
\font\ssl="\the\slface" at .7\fontsize%
\font\fsl="\the\slface" at .5\fontsize%
\fi%
\if&\the\bfface&%
\font\tbf="\the\rmface:embolden=3" at \fontsize%
\font\sbf="\the\rmface:embolden=3" at .7\fontsize%
\font\fbf="\the\rmface:embolden=3" at .5\fontsize%
\else%
\font\tbf="\the\bfface" at \fontsize%
\font\sbf="\the\bfface" at .7\fontsize%
\font\fbf="\the\bfface" at .5\fontsize%
\fi%
\if&\the\biface&\if&\the\itface&\font\tbi="\the\rmface:embolden=3:slant=.2" at \fontsize%
\else\font\tbi="\the\itface:embolden=3" at \fontsize\fi%
\else\font\tbi="\the\biface" at \fontsize\fi%
\if&\the\bsface&\if&\the\bfface&\font\tbs="\the\rmface:embolden=3:slant=.167" at \fontsize%
\else\font\tbs="\the\bfface:slant=.167" at \fontsize\fi%
\else\font\tbs="\the\bsface" at \fontsize\fi%
\if&\the\ttface&%
\else%
\font\ttt="\the\ttface" at \fontsize%
\font\stt="\the\ttface" at .7\fontsize%
\font\ftt="\the\ttface" at .5\fontsize%
\fi%
% Math font face definitions
\if&\the\mrmface&%
\font\mtrm="\the\rmface" at \fontsize%
\font\msrm="\the\rmface" at .7\fontsize%
\font\mfrm="\the\rmface" at .5\fontsize%
\ifnum\XeTeXfonttype\mtrm=0\let\mosy=\relax\else\font\mosy="\the\rmface:+onum" at \fontsize\fi%
\else%
\font\mtrm="\the\mrmface" at \fontsize%
\font\msrm="\the\mrmface" at .7\fontsize%
\font\mfrm="\the\mrmface" at .5\fontsize%
\ifnum\XeTeXfonttype\mtrm=0\let\mosy=\relax\else\font\mosy="\the\mrmface:+onum" at \fontsize\fi%
\fi%
\if&\the\mitface&%
\font\mtit="\the\itface" at \fontsize%
\font\msit="\the\itface" at .7\fontsize%
\font\mfit="\the\itface" at .5\fontsize%
\else%
\font\mtit="\the\mitface" at \fontsize%
\font\msit="\the\mitface" at .7\fontsize%
\font\mfit="\the\mitface" at .5\fontsize%
\fi%
\font\mtsy="\the\msyface" at \fontsize%
\font\mssy="\the\msyface" at .7\fontsize%
\font\mfsy="\the\msyface" at .5\fontsize%
\font\mtex="\the\mexface" at \fontsize%
\font\msex="\the\mexface" at .7\fontsize%
\font\mfex="\the\mexface" at .5\fontsize%
\if&\the\calface&%
\def\cal{\fam2}%
\else%
\font\tcal="\the\calface" at \fontsize%
\font\scal="\the\calface" at .7\fontsize%
\font\fcal="\the\calface" at .5\fontsize%
\textfont9=\tcal\scriptfont9=\scal\scriptscriptfont9=\fcal%
\def\cal{\fam9\tcal}%
\fi%
\if&\the\setface&%
\ifx\omathbb\relax\let\mathbb=\relax\else\let\mathbb=\omathbb\let\omathbb=\relax\fi%
\else%
\font\tset="\the\setface" at \fontsize%
\font\sset="\the\setface" at .7\fontsize%
\font\fset="\the\setface" at .5\fontsize%
\textfont10=\tset\scriptfont10=\sset\scriptscriptfont10=\fset%
\ifx\omathbb\relax\ifx\mathbb\relax\else\let\omathbb=\mathbb\fi\fi%
\def\mathbb####1{{\fam10\tset####1}}%
\fi%
% Family setup
\textfont0=\mtrm\scriptfont0=\msrm\scriptscriptfont0=\mfrm%
\textfont1=\mtit\scriptfont1=\msit\scriptscriptfont1=\mfit%
\textfont2=\mtsy\scriptfont2=\mssy\scriptscriptfont2=\mfsy%
\textfont3=\mtex\scriptfont3=\msex\scriptscriptfont3=\mfex%
\textfont4=\tit\scriptfont4=\sit\scriptscriptfont4=\fit%
\textfont5=\tsl\scriptfont5=\ssl\scriptscriptfont5=\fsl%
\textfont6=\tbf\scriptfont6=\sbf\scriptscriptfont6=\fbf%
\textfont7=\ttt\scriptfont7=\stt\scriptscriptfont7=\ftt%
\ifx\mosy\relax\else\textfont8=\mosy\scriptfont8=\mosy\scriptscriptfont8=\mosy\fi%
%
\rm%
\initrmfam%
\inititfam%
\initsyfam%
\initexfam%
(The code above follow the procession order, and not how it appears in the file)
The interesting part, that no matter what I removed, the next line that stood in its place become slow, so it may be independent from what is on that line.