Category: Development

Optimizing Source Code with AI

Optimizing Software Code using AI

Often in the release notes for our MIDAS room scheduling software, you may see the entry “Code Optimization”.

What is “Code Optimization”?

Code optimization is the process of refining our software’s source code to make it execute more efficiently, consume fewer resources, or improve its overall performance. It involves strategically modifying source code whilst at the same time ensuring the new code still produces the correct results.

Key goals of source code optimization:

  • Enhanced speed: Executing tasks more quickly
  • Reduced resource consumption: Using less memory, CPU cycles, or power
  • Improved scalability: Handling larger workloads effectively
  • Maintainability: Making code easier to understand and modify

Some common source code optimization techniques involve:

  • Algorithm optimization: Choosing more efficient algorithms
  • Loop optimization: Reducing loop iterations or overhead
  • Memory optimization: Minimizing memory usage and allocations
  • Input/output optimization: Streamlining data reading and writing
  • Caching: Storing frequently used data for faster access
  • Compiler optimization: Leveraging compiler features for automatic optimization
  • Profiling: Identifying performance bottlenecks to focus optimization efforts

Code Optimization in MIDAS

Over the years we’ve been developing MIDAS, all our code optimization work has been done manually.

This work has involved attempting to simplify and rewrite parts of the source code to be more efficient.

Code Optimizing with AI

In our latest release, MIDAS v4.35, for the very first time, a small section of source code has been optimized with the assistance of AI (or Artificial Intelligence).

We performed this AI code optimization as an experiment to see whether AI could potentially be used to aid our development processes in the future.

We chose a small “subroutine” from our software and asked an AI if it could optimize it for us.

A “subroutine” is essentially a small block of code which can be re-used and “called” repeatedly during a program’s execution.

The subroutine within the MIDAS software code that we asked an AI if it could optimize for us was basically a function which converts dates to “epoch” time.

Epoch time is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT).

How did the AI do?

Our original subroutine was 15 lines of code long. Using AI to optimize code, reduced this subroutine down to just 9 lines of code.

However, the initial source code that the AI generated for us did not just work “out of the box”. In fact, it didn’t work at all!

But using this AI generated code as a “template”, our team was able to modify the generated code so that it worked and produced the correct results.

Our team then extensively tested the new subroutine to ensure that it consistently produced the same expected output as the original subroutine.

Once we had a working subroutine that we were confident in, the next step was to “benchmark” the new routine against the old one. After all, there would be no point in using the new routine if there were no performance gains to be had, or indeed if the new code performed worse than the original.

To test this, we ran each subroutine 10,000,000 (10 million times), and analyzed the results:

Our Original Subroutine:
30 wallclock secs (30.28 usr + 0.00 sys = 30.28 CPU) @ 330229.18/s (n=10000000)

AI Optimized Subroutine:
27 wallclock secs (27.09 usr + 0.00 sys = 27.09 CPU) @ 369085.41/s (n=10000000)

To explain the above results, over 10 million iterations of each subroutine, the new AI optimized subroutine was more efficient. It ran (executed) quicker, and consumed less processing (CPU) power to achieve the same results as the original subroutine.

On our test server, the optimized subroutine was able to run 369,085 times in the space of one second, compared with 330,229 times in the space of a second for the original subroutine.

Ok, so the original subroutine was pretty quick and efficient to begin with – but with the assistance of AI, we were able to improve its efficiency by almost 12%.

Where do we go from here?

Firstly, don’t worry, Artificial Intelligence is not about to take over the development of our MIDAS software!

MIDAS has been – and will remain – coded, developed, and maintained by human programmers.

But our experiment – on a very small part of our code – has demonstrated that AI tools may be able to assist our human developers to write ever more efficient source code.

The result of such carefully applied optimizations is that our software can potentially run faster, use resources more efficiently, and provide a better overall user experience.


Generate Quotations For Prospective Bookings

MIDAS v4.35 introduces support for generating “Quotations” for prospective bookings.

Generate quotations when making tentative bookings
Generate quotations when making tentative bookings

Used in conjunction with the “Tentative Bookings” feature, you can generate quotations for clients when making tentative bookings for them.

Should the client accept and pay the quotation online, their “tentative” booking(s) automatically convert to regular “confirmed” bookings.

A number of configurable options are available with the new Quotations feature, including:

Automatically Update Booking Type

When a quotation is accepted and paid online, MIDAS can automatically update the corresponding booking’s “type” to be any confirmed booking type you’ve already defined.

Choose whether bookings become confirmed if their quotations are partially or fully paid

You can control when a “tentative” booking automatically converts to a “confirmed” booking based on how its associated quotation is paid.

Automatically change a booking's type when a quotation payments are received
Automatically change a booking’s type when a quotation payments are received

MIDAS can either “confirm” a tentative booking on just a partially paid quotation, or only confirm the booking once its quotation has been paid in full.

New Quotation Template

Templates” in MIDAS allow an administrator to customize a range emails, invoices, and more.

There’s already separate templates available for regular, deposit, and cancellation invoices, as well as receipts and credit notes.

v4.35 adds a further template now for your Quotations.

New customizable Quotation template
New customizable Quotation template

The default quotation template is very similar to the default regular invoice template, but introduces some new “placeholder” template variables too.

An example of a new placeholder variable available for the quotation template is “%QUOTEEXPIRES%”.

This special variable is substituted (at time the quotation is printed or emailed) with the date and time that the quotation expires.

By default, a quotation expires when its corresponding tentative booking(s) would expire in MIDAS.

However, there’s a further option available….

Variable quotation terms

As mentioned above, quotations by default are only valid up until the expiration time of their corresponding tentative booking(s).

So as an example, let’s say a tentative booking is made to commence at 9am on a Monday. The tentative booking settings are set to expire the booking if it’s not confirmed at least 2 hours before it is due to commence.

If the tentative booking hasn’t been confirmed by 7am on the Monday, the booking will automatically expire and be removed from the system.

In essence, a quotation generated for the above booking would remain valid until 7am on the day of the booking.

After this time, the quotation (and tentative booking) will have expired.

Now one of the new quotation options allows MIDAS to convert a tentative booking to a confirmed booking is only a partial payment has been made against the quotation.

In such instances, we’ve included an option to allow you to update the quotation’s terms to be the same as your standard invoice terms (i.e. for example 30 days).

Change a quotation's terms upon partial payment
Change a quotation’s terms upon partial payment

This means that as long as a client pays something towards the quotation, they will then have longer to pay the remaining balance, just as if they were paying a regular invoice.


Custom Validation For Required Fields

MIDAS ships with a set of standard booking and client input fields. These input fields allow you to capture specific details about a client and their bookings.

Standard Input Fields In MIDAS
Standard Input Fields In MIDAS

Now some of these fields will always be required. For bookings, a minimum of a date and a venue (room/bookable space) is required. All other booking fields can be set to be optional. Likewise, for clients, a minimum of the client’s name is required. All other client fields can be set to be optional.

Here’s a list of the standard fields which are included in MIDAS by default:

Default Booking FieldsDefault Client Fields
DateClient
Times (Booking)Organization
Times (Setup / Breakdown)E-mail Address
VenueMailing Address
Client / OrganizationTelephone Number
AttendeesFax Number
Booking TypeCell/Mobile Number
Booking NotesClient Notes
Resources

MIDAS also allows you to “turn off” fields that you don’t need. So if you don’t need to capture a client’s fax number, you can disable that field.

But that’s not all – in addition to the standard “default” fields, you can create additional custom booking or client fields in MIDAS.

Adding Custom Fields

A range of different types of custom fields can be created, including:

  • Checkbox – A “tick box” field.
  • File – Allows uploading/attaching of files and documents to bookings or client records (self-hosted systems only)
  • List (Single Select) – A drop-down list of pre-defined items from which a single item may be selected.
  • List (Multi Select) – A drop-down list of pre-defined items from which multiple items may be selected.
  • Number – A field that will only accept numerical input.
  • Range – A “slider” control allowing selection of a numeric value within a defined range.
  • Text – A single-line text field.
  • Text Area – A multi-line text field.
  • URL – A navigable web link to an external resource.

As with standard fields, custom fields can also be set to be “required”. This means that an input is required in the custom field each time it’s shown.

New Validation Feature

For MIDAS v4.34, we’re extending the capabilities of marking custom number, text, text area, and URL fields “required”.

Let’s take the example of a custom single-line text field. Marking this as a required field would ensure that a user would enter something into the field. However, MIDAS wouldn’t check what they’d actually entered. Just entering a single character, or gibberish would be enough to allow you to proceed.

From v4.34 onwards, when setting a custom number, text, text area, and URL field as “required”, you can instruct MIDAS what values are considered “valid” for the field. A user would then need to enter a “valid” value in order to proceed.

Custom Field Validation Using Regular Expressions
Custom Field Validation Using Regular Expressions

A Simple Example

As an example, you could make it so that a user has to enter the word “YES” into a custom text field in order to proceed. If the custom field doesn’t contain the word “YES”, the user will be prompted to correct their entry:

Require Valid Entries In Custom Fields
Require Valid Entries In Custom Fields

The Power Of REGEX

Regular Expressions (REGEX) can be used to create more complex validations for your custom fields too. We’ll cover REGEX in more depth in a future article. In the meantime, as a brief introduction, here are a few simple yet useful REGEX’s for validating entries into your custom fields:

DescriptionREGEX
Value must start with the letters “BOOK”^BOOK
Value must end with the letters “ING”ING$
Value must contain “BOOKING”BOOKING
Value must be exactly “BOOKING”^BOOKING$
Value must contain a number (digit)\d
Value must not contain a number (digit)\D
Value must be exactly “BOOK”, followed by two single digit numbers^BOOK\d\d$

You’ll find further examples together with detailed explanations in our KB article: How to use Regular Expressions for custom input validation.

How To Use

Custom field validation can be setup via MIDAS Admin Options → Manage MIDAS → Fields.

On any custom number, text, text area, or URL fields, right-click (or long press on touch screens) on the field’s “Required” box.

You’ll then be able to set or modify the Regular Expression that should be used to validate entries to the field.


Schedule regular Security Audits

You may not know, but MIDAS includes a built-in “Security Audit” tool.

This allows you to perform a quick and on-demand security analysis of your MIDAS system.

Perform a detailed Security Audit of your MIDAS room booking system
Perform a detailed Security Audit of your MIDAS room booking system

First introduced with the release of MIDAS v4.13 in 2016, the “Security Audit” tool tests a number of key metrics of your MIDAS booking system.

The audit checks your MySQL / MariaDB setup, MIDAS files, and recommended MIDAS security settings.

It provides a detailed report with appropriate advisories for hardening the security of your MIDAS system.

When the Security Audit was first introduced, it analyzed 15 metrics. Today, that number has increased to over 20.

For MIDAS v4.33, the audit now additionally also…

  • Indicates the number of recently failed login attempts to your MIDAS system.
  • Checks whether Geofenced logins have been enabled.

But the biggest improvement to Security Audits for MIDAS v4.33 is the ability to schedule regular automated security audits.

Until now, a Security Audit could only be manually initiated (via MIDAS Admin Options → Manage MIDAS → Security → Perform a Security Audit)

From MIDAS v4.33, you can now use Scheduled Tasks to automatically run a Security Audit and email you the results. Audits can be configured to run every 7, 14, 30, 60, or 90 days.

Schedule automated security audits of your MIDAS booking system
Schedule automated security audits of your MIDAS booking system