Skip to content

Use numbers instead of strings for the DBActions and SyncEvents constants #6815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 20, 2025

Conversation

absidue
Copy link
Member

@absidue absidue commented Feb 16, 2025

Use numbers instead of strings for the DBActions and SyncEvents constants

Pull Request Type

  • Performance improvement

Description

Currently we use string values in our DBActions and SyncEvents constants. While there is nothing wrong with doing that, there are definitely a few advantages, such how long some of the strings have become e.g. sync-subscriptions-update-shorts-with-channel-page-shorts-by-channel.

It is a well known fact that computers are great at crunching numbers, so switching to number values should not only be more performant but will also lower memory use and the bundle sizes (-1379 bytes from both the main.js and renderer.js files).

From a development perspective this shouldn't have a big impact as we still have the human readable variable names and there is a code comment explaining that the numbers need to be unique/not overlap, so I don't think this will impact maintainance too much.

If you are wondering why I didn't do the same to the IpcConstants, it is because Electron requires string values for the IPC channel names.

Testing

  1. Open multiple windows
  2. Check that changing a setting, modifying playlists and refreshing subscriptions for example get synced properly between windows. That tests that they arrived correctly in the main process via the DBActions constants and got forwarded to the other window with the SyncEvents constants.

Desktop

  • OS: Windows
  • OS Version: 10
  • FreeTube version: 0464d90

@FreeTubeBot FreeTubeBot enabled auto-merge (squash) February 16, 2025 22:09
@github-actions github-actions bot added the PR: waiting for review For PRs that are complete, tested, and ready for review label Feb 16, 2025
Copy link
Collaborator

@PikachuEXE PikachuEXE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's easer to start other groups on 11 or even 101 so that if a few things are added to GENERAL there is no need to reassign values for other groups

@absidue
Copy link
Member Author

absidue commented Feb 19, 2025

I've bumped the numbering for the other categories to start at 20, that gives us 14 more spots in the DBActions and 15 in the SyncEvents constants. Which leaves us a decent amount of flexibility without chosing numbers that are unnecessarily large.

@FreeTubeBot FreeTubeBot merged commit 0b9361f into FreeTubeApp:development Feb 20, 2025
5 checks passed
@github-actions github-actions bot removed the PR: waiting for review For PRs that are complete, tested, and ready for review label Feb 20, 2025
PikachuEXE added a commit to PikachuEXE/FreeTube that referenced this pull request Feb 20, 2025
* development: (58 commits)
  Convert FtSubscribeButton and watch-video-info SCSS to CSS (FreeTubeApp#6814)
  Use numbers instead of strings for the DBActions and SyncEvents constants (FreeTubeApp#6815)
  Translated using Weblate (English (United Kingdom))
  Fix: search history text overflows if search term is long (FreeTubeApp#6728)
  Check if a keyboard composition session is active when pressing 'Enter' on ft-input (FreeTubeApp#6799)
  use hq img (FreeTubeApp#6826)
  Move the choose default folder logic to the main process (FreeTubeApp#6811)
  Translated using Weblate (French)
  Translated using Weblate (Turkish)
  Set process.platform at build time (FreeTubeApp#6784)
  Use logical spec for float (FreeTubeApp#6783)
  Migrate DataSettings to the composition API (FreeTubeApp#6785)
  Local API: Improve audio quality by sorting streams, highest bitrate first (FreeTubeApp#6807)
  Bump sass from 1.84.0 to 1.85.0 (FreeTubeApp#6825)
  Bump webpack from 5.97.1 to 5.98.0 (FreeTubeApp#6820)
  Bump postcss from 8.5.1 to 8.5.2 in the stylelint group (FreeTubeApp#6819)
  Bump the babel group with 2 updates (FreeTubeApp#6817)
  Bump globals from 15.14.0 to 15.15.0 (FreeTubeApp#6823)
  Bump sass-loader from 16.0.4 to 16.0.5 (FreeTubeApp#6822)
  Bump eslint from 9.20.0 to 9.20.1 in the eslint group (FreeTubeApp#6818)
  ...

# Conflicts:
#	src/renderer/components/watch-video-info/watch-video-info.scss
#	src/renderer/components/watch-video-info/watch-video-info.vue
@absidue absidue deleted the numeric-constants branch February 20, 2025 05:17
doublecrow pushed a commit to doublecrow/FreeTube that referenced this pull request Mar 28, 2025
…ants (FreeTubeApp#6815)

* Use numbers instead of strings for the DBActions and SyncEvents constants

* Fix duplicate number

* Start offset numbers at 20
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.

5 participants