How to save the caching produced in processing

As my this previous post.I get a custom function which can help me got some function contain a certain option.And I have put it in my "init.m" file.

LookupOptionFunction[option_] :=
Select[ToExpression[
Complement[
Select[Names["System*"],
StringFreeQ["$"]], {"AllowTransliteration", "MyFind"}]], KeyMemberQ[Options[#1], option] &] Usage: LookupOptionFunction[SelfLoopStyle] {GraphPlot, GraphPlot3D, LayeredGraphPlot, TreeForm, TreePlot} But there are some problem As the @Bob Hanlon's answer,the speed up due to the caching produced in first time to run it. My Question How to save the caching to help me speed up to run it even we restart the Mathematica? New progress: I exclude the Keys@SystemOptions[] one by one and narrow it down from 90 to 17,I think following system options must can implement this demand: {"CacheOptions","CatchMachineUnderflow","DataOptions","DefinitionsReordering","DifferentiationOptions","DynamicLibraryOptions","EnforceCallPacket","FileBackedCachingOptions","GlobFileNames","HolonomicOptions","LegacyFrontEnd","LegacyNewlineParsingInStrings","NeedNotReevaluateOptions","PostScriptBufferSize","RestorePackageDependencies","SymbolicProductThreshold","SymbolicSumThreshold"} But I don't familar they by name.Maybe we just have a little bit of a difference 2 Answers The behavior you are encountering is the time taken by Mathematica evaluate all the Symbols in the System context, including definitions (and Options) that are only loaded on first use. (For one of my own encounters with this delayed loading please see Why do I have to evaluate this twice?) In a fresh Kernel observe that GraphPlot has no Options: Quit[] (* quit the Kernel, then separately evaluate the line below *) Options @ Unevaluated @ GraphPlot {} But when it is evaluated its definitions are loaded and it then has Options: GraphPlot; (* seemingly inert command that pre-loads GraphPlot definitions *) Options @ Unevaluated @ GraphPlot {AlignmentPoint -> Center, AspectRatio -> Automatic, Axes -> False, . . . If we prevent all pre-loading and other evaluation by using Unevaluated as I did in the first example the initial search is quite fast: Quit[] (* quit the kernel first *) nopreloadLookupOptionFunction[option_] := Complement @@ Names /@ {"System*", "System\\$*"} // ToHeldExpression //
Cases[ Hold[s_Symbol] :> s /; Quiet @ Options[Unevaluated @ s, option] =!= {} ]

{0.132444, {TreeForm}}

However we no longer have Symbols like GraphPlot etc. in the list because at the time of evaluation these had no Options. We therefore need to know which Symbols to preload, or which to not evaluate (because they are slow). I believe we can use the OwnValues of a Symbol to determine if it needs preloading by looking for the appearance of SystemDumpAutoLoad. Implementing this idea we have my

Proposed solution

If[! FreeQ[Quiet @ OwnValues @ Unevaluated @ sym, SystemDumpAutoLoad], sym;]

fastLookupOptionFunction[option_] :=
Names["System*"] // ToHeldExpression //
Cases[
Hold[s_Symbol] :>
s /; (preload @ s; Quiet @ Options[Unevaluated @ s, option]) =!= {}
]

Which in a fresh kernel yields:

fastLookupOptionFunction[SelfLoopStyle] // AbsoluteTiming
{1.47235, {GraphPlot, GraphPlot3D, LayeredGraphPlot, TreeForm, TreePlot}}

If this is still not fast enough for you or misses Options that are loaded in another way besides SystemDumpAutoLoad I suggest that you construct a separate database of the Symbol and Option names that you can search independent of evaluation.

• Wonderful solution.. – yode Jul 7 '16 at 22:47
• @yode Thank you :-) – Mr.Wizard Jul 7 '16 at 23:06

You may make use of the built-in index caching for Entity objects; "WolframLanguageSymbol".

lookupOptionFunction[optionName_String] :=
ToExpression /@
EntityValue[EntityList[
Entity["WolframLanguageSymbol",
{EntityProperty["WolframLanguageSymbol", "OptionNames"] -> optionName}]],
"Name"]]

First run after creating lookupOptionFunction.

lookupOptionFunction["Alignment"] // AbsoluteTiming