Karsten Schmidt<p>Thanks to <span class="h-card" translate="no"><a href="https://mastodon.gamedev.place/@made" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>made</span></a></span> I recently learned that dynamic code generation doesn't play nice with certain Content Security Policies (CSP). This has a major impact on a few core packages in <a href="https://mastodon.thi.ng/tags/ThingUmbrella" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>ThingUmbrella</span></a>, like the <a href="https://thi.ng/vectors" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="">thi.ng/vectors</span><span class="invisible"></span></a> package which contains ~900 vector functions, most of them code generated and optimized for different vector sizes/dimensions (incl. n-dimensional versions). This package (and some others using a similar approach) are key dependencies for dozens of other geometry/visualization related packages... However, I found code generation the only way to practically manage & maintain the sheer amount of functionality provided.</p><p>Because of this (CSP impact), I've been working on a new code generator, which converts the dynamically generated code into statically generated source code files. This will make the overall initial package size bigger, but this shouldn't be a major problem in practice, since there're also very positive effects, including:</p><p>- The new format allows for doc strings for _all_ generated vector ops (with the dynamic approach there was no way to properly attach those in TypeScript)<br>- The new file structure (single function per source file) massively helps with dead code elimination when using a bundler, resulting in smaller final file/bundle sizes. When NOT using a bundler, similar filesize savings can be had by using direct imports (to individual functions) rather than full package imports<br>- None of the unused versions need to be code generated at runtime anymore, so also improving startup time</p><p>The new codegen is already covering around more than a third of the 900 ops. If you want to keep an eye on progress & discussion, follow this issue:</p><p><a href="https://github.com/thi-ng/umbrella/issues/497" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">github.com/thi-ng/umbrella/iss</span><span class="invisible">ues/497</span></a></p><p><a href="https://mastodon.thi.ng/tags/ThingUmbrella" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>ThingUmbrella</span></a> <a href="https://mastodon.thi.ng/tags/CodeGenerator" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>CodeGenerator</span></a> <a href="https://mastodon.thi.ng/tags/TypeScript" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>TypeScript</span></a> <a href="https://mastodon.thi.ng/tags/Vector" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Vector</span></a> <a href="https://mastodon.thi.ng/tags/PSA" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>PSA</span></a></p>