Skip to content

Conversation

@icgmilk
Copy link

@icgmilk icgmilk commented Apr 27, 2025

Use existing hashmap utilities to replace ALIASES and CONSTANTS.

Previously, "find_alias" and "find_constant" performed linear searches (O(n)). With the hashmap, search time is reduced to O(1) on average.

Benchmark for ./src/main.c compilation

Before: /usr/bin/time -v ./out/shecc ./src/main.c

Command being timed: "./out/shecc ./src/main.c"
        User time (seconds): 0.19
        System time (seconds): 0.08
        Percent of CPU this job got: 100%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.28
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 312640
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 88079
        Voluntary context switches: 1
        Involuntary context switches: 3
        Swaps: 0
        File system inputs: 0
        File system outputs: 472
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

After: /usr/bin/time -v ./out/shecc ./src/main.c

Command being timed: "./out/shecc ./src/main.c"
        User time (seconds): 0.13
        System time (seconds): 0.09
        Percent of CPU this job got: 99%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.22
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 312320
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 88015
        Voluntary context switches: 1
        Involuntary context switches: 2
        Swaps: 0
        File system inputs: 0
        File system outputs: 472
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

Summary by Bito

This pull request introduces performance enhancements by replacing ALIASES and CONSTANTS arrays with hashmaps, optimizing search operations from O(n) to O(1). The changes include new hashmap variables and updates to related functions for improved efficiency.

Unit tests added: False

Estimated effort to review (1-5, lower is better): 2

Use existing hashmap utilities to replace ALIASES and CONSTANTS.

Previously, "find_alias" and "find_constant" performed
linear searches (O(n)). With the hashmap, search time is reduced
to O(1) on average.
@jserv jserv merged commit f3bf67a into sysprog21:master May 1, 2025
6 checks passed
@jserv
Copy link
Collaborator

jserv commented May 1, 2025

Thank @icgmilk for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants