Emacs Extensions for
GE Smallworld Magik Development

Screen-casts, tutorials, and productivity tools for Magik programmers who use Emacs. From tab-mode and code folding to the Magik Debugger and object inspector — explore features built by a developer, for developers.

Learn More
HydePark Consulting Screen-casts on YouTube RSS via FeedBurner

Nine screen-casts published between November 2010 and January 2011 — covering everything from ECB mode to the Tree Item GUI control. Read the story behind the project →

Get in Touch

Tracing Magik's Performance Bottlenecks in Emacs

Magik's performance bottlenecks often sit in ordinary-looking code: a loop over a large collection, repeated property access, an unnecessary transaction, or a call that waits on the database. These costs are easy to misattribute because the visible symptom is usually a slow Smallworld operation. Profiling with Emacs' profiler replaces guesswork with a measured call path, showing where elapsed time accumulates and which methods deserve attention first.

The useful workflow is deliberately boring: capture a representative workload, start the appropriate profiler, run the same method several times, and preserve both the report and its context. Emacs is valuable here because the call graph and source navigation stay close together, while Magik inspection tools can expose the objects and collections moving through the hot path. This article explains how to build that workflow without confusing Emacs Lisp timing with remote Magik execution.

Build a repeatable baseline

Begin with a slow but bounded operation that can be repeated without changing business data. Record the method name, transaction or action, Smallworld release, dataset, object count, and input identifiers. Take several timed samples rather than trusting one run, and separate cold state from warm state. If the method is freshly compiled, operates on an empty cache, or follows a full restart, that context belongs beside the first result.

Measure from the same place used for support. Australian teams in Sydney, Melbourne and Brisbane often reach an on-site Smallworld server through a managed VPN, so laptop-to-server latency can make an interactive call feel slower than server CPU time. Capture elapsed time at Emacs and, where available, server-side timing. Profile during a representative nine-to-five window as well as a quieter period to expose contention on shared networks and batch systems.

Align timestamps before comparing runs. Sydney and Melbourne observe daylight saving, while Brisbane remains on Australian Eastern Standard Time, so an overnight batch can start at a different clock time relative to office activity. A trace made during the busy interval may include resource contention that a Sunday profile misses. Keep the machine, database connection, and relevant process state stable, and annotate any changed condition rather than folding it into the measured code.

Prepare the workload for measurement

Choose the smallest representative workload, not a toy that avoids the expensive data. A single parcel, network asset, customer record, or geometry may not reproduce the collection size or spatial operation seen in production. Capture input shape, row count, and expected output. Keep sensitive values out of method arguments and saved reports, but retain enough metadata to distinguish two datasets with similar names.

Make navigation part of the setup. When definitions are split across packages, Emacs' method navigation guide shows how jump-to-definition can move from a profiler label to the exact Magik source. Follow each expensive branch into its helper methods and note whether they are local calls, package calls, or transaction-managed work. This avoids treating a visible method as the root cause when most of its time is spent in a child operation.

Use workloads familiar to Australian geospatial and infrastructure projects. Depending on the business, that may mean GDA2020 coordinates, ABS Census boundaries, state cadastre extracts, council assets, utility networks, or bushfire-hazard layers. These inputs expose different costs: coordinate transforms, geometry predicates, large keyed collections, and repeated lookups. Test with representative cardinality and geometry complexity, because a reduced sample can make an inefficient algorithm appear perfectly acceptable.

Read the profiler as a call graph

Know which profiler is running. Emacs' built-in profiler-start, profiler-stop, and profiler-report profile Lisp evaluation; they do not automatically time Magik methods executing on a Smallworld server. For a remote Magik workload, use the profiler instrumentation provided by your Smallworld release or Magik Emacs tooling, then feed those events into the Emacs report. If the integration is absent, instrument the Magik side or measure it with server facilities before interpreting an Emacs-only profile.

Start before dispatching the method, execute one isolated workload, and stop promptly afterward. In the report, look for total time, self time, sample count, and the call graph. Total time includes children and identifies an expensive branch; self time points to work performed directly inside a method. Sort by cost, but inspect call count as well: a moderately expensive helper called thousands of times may cost more than the largest individual entry.

Read percentages with care. A short run produces coarse samples, and profiler overhead can distort very fast methods. Recursive calls, lazy evaluation, error paths, and work performed by a database or service may also appear differently from ordinary Magik calls. Confirm a suspected hotspot by adding a focused timer or by running a controlled variation, such as removing one collection scan. The profiler should nominate an experiment, not replace one.

Separate computation from waiting

Compare elapsed time with processor time. If both climb together, inspect loops, allocation, property access, sorting, geometry calculation, and string construction in Magik. If elapsed time rises while server CPU stays flat, the method is probably waiting. That distinction prevents an expensive-looking Magik frame from being rewritten when the real delay is a connection timeout, lock wait, or storage request.

Follow waiting branches to their boundary. A transaction that calls a remote datastore, a lock acquired around shared records, or a network service can dominate the trace without consuming much Magik CPU. Record the database or service involved, the latency distribution if available, and whether the call sits inside a transaction. For large collections, inspect iteration counts and lookup patterns; repeated linear scans can resemble I/O stalls even when everything remains local.

Use Magik's object inspection and collection analysis tools beside the profiler. Confirm how many elements a vector, hash table, property map, or domain collection contains, whether key types match, and whether objects are rebuilt during iteration. Compare structural facts with the profile: a million-element collection visited twice explains more than a high percentage on its own. Avoid drawing conclusions from object counts gathered after a method has already transformed the data.

Test focused changes under realistic load

Change one likely cause at a time. Replace repeated linear searches with an indexed lookup where the data model permits it, choose a collection suited to the access pattern, or move invariant work outside a loop. Cache a value only when its lifetime and invalidation rules are clear; transaction state and mutable Smallworld objects can change underneath a shortcut. Keep the patch narrow enough that the before-and-after report explains the gain.

Rerun the same workload under the same conditions, using multiple samples and reporting median and worst-case duration separately. Include throughput and memory behaviour when the operation runs as a batch. For user-facing actions, compare the complete Emacs-to-response path; for scheduled jobs, use total runtime, peak resource use, and collection processing time. A faster inner method is useful only if the end-to-end result improves without changing correctness.

Protect the data used to test. Australian council, utility, and land-registry workloads may contain customer names, addresses, asset locations, or other personal information. The Privacy Act 1988 and Australian Privacy Principles can apply, with state privacy legislation adding obligations in some settings. Replace identities with stable test tokens, limit exported profiler data, and keep raw captures in approved Australian-hosted or on-site storage according to the organisation's policy.

Turn measurements into a shared feedback loop

Keep a compact performance note with each change. Include the baseline and revised reports, source revision, Smallworld release, data description, timing method, and environmental conditions. Record whether the result is a confirmed fix, an inconclusive sample, or a regression. This prevents a promising local measurement from becoming folklore and gives the next maintainer enough evidence to reproduce the result months later.

Share the method and result with the people who maintain the surrounding workflow. Colleagues can check assumptions about transaction boundaries, datastore behaviour, or collection design before an optimisation spreads. Relevant meet-ups, user groups, and conference listings are available through the H4H conference site. Present the timing evidence and workload shape rather than naming a method as slow without context; concrete measurements make the discussion useful to other Magik teams.

Install or update the Magik Emacs tooling, select one operation with a visible delay, and capture a profiler report today. Save it beside a repeatable test script and establish the baseline before touching the implementation. Then rerun that same workload after each focused change and keep the evidence with the source. A preserved baseline and a disciplined rerun turn a one-off profiling session into a durable performance practice for the whole Magik team.

Core Features

Tab Mode & ECB

Quick tab switching and Emacs Code Browsing mode for navigating Magik codebases efficiently.

Magik Smeller

Code analysis tool that helps identify potential issues in Magik source files.

Code Folding

Hide/Show mode for collapsing and expanding Magik code blocks to focus on what matters.

Visual Bookmarks

Quick visual bookmarks for jumping between key locations in your Smallworld session buffers.

Object Inspector

Inspect Magik objects and display them in an Emacs Deep Print buffer for detailed examination.

Magik Debugger

Set breakpoints and monitor slots and variables directly from within Emacs.

Development Tools

Direct links between Emacs and the Smallworld Development Tools application, including Click Monitor.

Screen-casts & Tutorials

Dark code editor window with syntax-highlighted Magik source code in muted blues and greys, conveying a focused development environment

Screen-cast 1: Tab Mode, ECB & More

Covers tab-mode, ECB, Magik Smeller, code folding, visual bookmarks, pragma toggling, moving code, external editor, and MS Explorer.

November 7, 2010
Split-pane Emacs interface with multiple buffers open, warm amber and navy tones against a dark background

Screen-cast 5: Object Inspection & Deep Print

Inspect a Magik object, prompt for an expression evaluated within a Smallworld session, and display results in a Deep Print buffer.

January 16, 2011
Debugging interface with breakpoint markers and variable watch panels in subdued teal and charcoal tones

Screen-cast 7: Magik Debugger

Useful tools for application developers: Object Inspector and Magik Debugger with breakpoints and slot/variable monitoring.

January 2011
Tree control GUI element with expandable branches rendered in clean greys and muted blues on a light background

Screen-cast 9: Tree Item GUI Control

Tree Item is a GUI control providing extensive facilities for displaying lists with rows, columns, trees, and in-place editing.

January 20, 2011