Diet program with preprocessor (how to deal with i-appli size)

Currently, most mobile devices are smartphone iPhones and androids. Do you know the upper limit of the size of each app? As of August 2020, the iOS app is 4GB and the android app is 100MB.

Looking at this, there is a big difference ... I wonder if android uses a method to download data later for large-capacity games. I haven't written the heap in detail, but since the terminal has a few GB of memory, it shouldn't be a big problem.

However, what I would like to talk about this time is the future phone (= feature phone) that was active as a mainstay before the birth of smartphones, and the story of DoCoMo's i-appli.

I would like to introduce that the early development method of DoCoMo's i-appli was the result of tearful efforts.

DoCoMo i-appli size

Time goes back to the era of feature phones. I recognize that it was DoCoMo's i-appli that pulled the feature phone app world, but what was the size limit at that time?

The following is the information of the application on the DoJa-1.0 profile that was released at the beginning.

Model App size (KB) Heap capacity(KB)
FOMA N2001 10 96
FOMA N2002 10 560
FOMA P2101V 30 1100
FOMA D2101V 10 128
FOMA P2002 10 560
FOMA SH2101V 30 1024
FOMA T2101V 30 1105

Official page https://www.nttdocomo.co.jp/service/developer/make/content/spec/iappli/#notice05

The minimum app size was 10KB and the heap capacity was 96KB. There is a separate native heap, and it seems that the memory on the terminal side can be used a little, but this capacity in the pure Java part.

The app size is a Jar file that includes bytecode compiled from code and resources such as images. This was limited to 10KB (10240 bytes).

You may only be conscious of it, so let's check how much it is. However, it is difficult to build an i-appli development environment, so we will compare with the android app size as of August 2020.

I think I chose an app that seems to have relatively few functions, but MB units are natural. Since things and times are different, it is not possible to make a general comparison, but I cannot imagine that it will fit within 10KB.

Early app development code

I know that the size of the i-appli is extremely strict, but I wonder how it was made. The only element to scrape is the program.

It's true that you can't do what you want because you'll run out of features if you cut the program, but there's one way to reduce the size without reducing the features. That is to make variable names, class names, and method names smaller.

The code is written in a fairly appropriate way, but for example, it looks like this.

Change before


public class MainFrame {
 
    private static final String TITLE = "Sample app";
    private static final String ERROR_MESSAGE = "An error has occurred";
 
    public void showFrame() {
        try {
            //Some processing
        } catch (Exception e) {
            showMessage(ERROR_MESSAGE);
        }        
    }
 
    public void showMessage(String message) {
        //Message display processing
    }
}

After change


public class F {
 
    private static final String A = "Sample app";
    private static final String B = "An error has occurred";
 
    public void s() {
        try {
            //Some processing
        } catch (Exception e) {
            m(B);
        }
    }
 
    public void m(String s) {
        //Message display processing
    }
}

If you reduce the number of characters in the variable name and method name, the number of characters written in the compiled class file will decrease, so you can expect a reduction in size. Anyway, it's an energy saving program.

A program of this size can still be read, but it is obvious that the more you build it, the worse it becomes. How did you clear this problem?

The evil way of preprocessor + Java

After narrowing down his wisdom, his ancestors decided to use something that the Java language does not. It is a preprocessor often used in C languages.

Specifically, write the following code.

Preprocessor version code


#define _MainFrame     F
#define _TITLE         A
#define _ERROR_MESSAGE B
#define _showFrame     s
#define _showMessage   m
  
public class _MainFrame {

    private static final String _TITLE = "Sample app";
    private static final String _ERROR_MESSAGE = "An error has occurred";

    public void _showFrame() {
        try {
            //Some processing
        } catch (Exception e) {
            _showMessage(_ERROR_MESSAGE);
        }
    }

    public void _showMessage(String s) {
        //Message display processing
    }
}

The syntax below means converting the letter "_MainFrame" to the letter "F".

python


#define _MainFrame     F

This part is not Java syntax, so of course it cannot be compiled with a Java compiler. So let's go through the preprocessor. Then, the following code is completed.

public class F {
  
    private final String A = "Sample app";
    private final String B = "An error has occurred";
  
    public void s() {
        try {
            //Some processing
        } catch (Exception e) {
            m(B);
        }
    }
  
    public void m(String s) {
        //Message display processing
    }
}

Now that you can compile it, all you have to do is build normally.

By passing the code with macros in two stages, preprocessor → Java compiler, you can reduce the size while improving readability. I think it was hard because I can't use the IDE.

Finally

This article is based on the idea of using a preprocessor that I saw on another site nearly 10 years ago. The site doesn't exist anymore, but I wrote it because I wanted to keep the idea.

Recommended Posts

Diet program with preprocessor (how to deal with i-appli size)
[Rails / RSpec] How to deal with element has zero size error
[Android] How to deal with dark themes
How to deal with Precompiling assets failed.
How to deal with fatal: remote origin already exists.
How to deal with No template for interactive request
[Docker environment] How to deal with ActiveSupport :: MessageEncryptor :: InvalidMessage
[Rails] How to deal with URL changes after render
Common problems with WSL and how to deal with them
[Docker + Rails] How to deal with Rails server startup failure
How to number (number) with html.erb
How to update with activerecord-import
How to deal with the error ERROR: While executing gem ... (Gem :: FilePermissionError)
How to deal with Bundler :: Dsl :: DSLError by rewriting gemfile
How to deal with different versions of rbenv and Ruby
How to scroll horizontally with ScrollView
How to get started with slim
How to deal with 405 Method Not Allowed error in Tomcat + JSP
How to enclose any character with "~"
Android: How to deal with "Could not determine java version from '10 .0.1'"
How to use mssql-tools with alpine
Project facet Java version 13 is not supported. How to deal with
How to get along with Rails
How to deal with the type that I thought about writing a Java program for 2 years
How to start Camunda with Docker
Java8 / 9 Beginners: Stream API addiction points and how to deal with them
How to crop an image with libGDX
How to adjustTextPosition with iOS Keyboard Extension
How to share files with Docker Toolbox
How to compile Java with VsCode & Ant
[Java] How to compare with equals method
How to use BootStrap with Play Framework
[Rails] How to use rails console with docker
How to switch thumbnail images with JavaScript
[Note] How to get started with Rspec
[Introduction to Java] How to write a Java program
Ruby length, size, count How to use
[Java] How to measure program execution time
How to do API-based control with cancancan
How to achieve file download with Feign
How to update related models with accepts_nested_attributes_for
How to set JAVA_HOME with Maven appassembler-maven-plugin
How to implement TextInputLayout with validation function
How to handle sign-in errors with devise
How to delete data with foreign key
How to test private scope with JUnit
How to monitor nginx with docker-compose with datadog
How to achieve file upload with Feign
How to run Blazor (C #) with Docker
How to build Rails 6 environment with Docker
[Laravel] How to deal with out of memory error when composer require [Docker]
Challenge to deal with garbled characters with Java AudioSystem.getMixerInfo ()
How to download Oracle JDK 8 rpm with curl
[Java] How to test for null with JUnit
How to mock each case with Mockito 1x
[Java] How to use Thread.sleep to pause the program
How to mock each case with PowerMock + Mockito1x
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
How to save to multiple tables with one input
How to test interrupts during Thread.sleep with JUnit
How to use built-in h2db with spring boot