Codegen at Runtime

Codegen is usually used at build time to produce source code for an application.
However I have recently found a use for it at runtime (although infrequently).

The application that I work on has an archive process that takes the older data away to a secondary database. Periodically a new archive database is created.

We used to use dynamic sql within a stored procedure to move the data from the live to the archive. Strings were constructed within a stored procedure and executed. This turned out to be too slow.

I replaced the dyamic sql with a set of stored procedures that were regenerated at archive creation time using XSLT. This is exactly the same technique as traditional code generation, but  has provided a massive speed increase (3X to 7X improvements have been seen).

One thought on “Codegen at Runtime

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s